1: #line 4861 "./lpsrc/flx_tutorial.pak" 2: //Check match:float 3: //Check nan 4: #import <flx.flxh> 5: 6: match (1.0) with 7: | NaN => { print "Not a Number"; } 8: | -inf .. -0.999 => { print "lt -1"; } 9: | -1.001 .. 1.001 => { print "Unit circle"; } 10: | 0.999 .. inf => { print "Greater than 1"; } 11: endmatch; 12: endl; 13: 14: match (1.0) with 15: | 0.999 .. 1.001 => { print "one"; } 16: endmatch; 17: endl; 18: 19: match (1.0/3.0) with 20: | 0.3333 .. 0.3334 => { print "One third"; } 21: endmatch; 22: endl;
1: Unit circle 2: one 3: One third
A range test is neither inclusive nor exclusive! That's why there is no test for a particular float, and why the ranges above overlap. Welcome to constructive mathematics!
Note that _floating_ point provides exact comparisons; however, the patterns above apply to constructive reals. The last example explains this best: you can't do non-constructive matches. [Use IEEE type for exact FP?]