Hi Joel Yup. You got it. The eq? (etc.) functions are convenient, but I prefer (provided we get the correct answers!) the infix notation. Also, the infix comparison operators are faster than the prefix operators. Positive? (etc.) is currently the fastest way to make correct comparsions, although a little cumbersome. And of course, the native functions equal? etc. work across all the different datatypes while my quick fix only works for numbers. Here are more fun examples illustrating the comparison problem. In the interval from 2 ** 52 to 2 ** 53, IEEE754 doubles are spaced apart by exactly 1, (i.e., they are all consecutive integers). This makes this range a convenient one for testing comparisons, examining round-off, etc. >> x: 2 ** 52 ;= 4503599627370496 == 4.5035996273705E+15 ;REBOL display rounded >> y: x + 1 ;the next double= 4503599627370497 == 4.5035996273705E+15 ;REBOL display rounded >> x = y == true ;should be false >> = 0 y - x == false ;should be false >> zero? y - x == false ;should be false >> positive? y - x == true ;should be true >> y > x == false ;should be true >> y - x == 1 ;result of subtraction >> zero? y - x - 1 == true ;the answer 1 is exact Notice that in this case (= x y) is incorrect but (= 0 y - x) is correct. Cheers Larry ----- Original Message ----- From: <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> Sent: Saturday, January 22, 2000 10:05 PM Subject: [REBOL] "Writer's block" -- Nondeterministic REBOL Re:(2) > Thanks, Larry! I appreciate the alert. > > [EMAIL PROTECTED] wrote: > > > > ... The problems are due to a flaw in the mathematical comparison > > functions (< > <> = <= >=) in REBOL when they are applied to the > > decimal! type... > > > > So, to avoid stepping on this land-mine, I should either define the > "safe" comparisons per your note or rewrite > > > > > > > signum: func [n [number!]] [ > > > ewd/if [ > > > n < 0 [-1] > > > n = 0 [ 0] > > > n > 0 [ 1] > > > ] > > > ] > > signum: func [n [number!]] [ > ewd/if [ > negative? n [-1] > zero? n [ 0] > positive? n [ 1] > ] > ] > > and > > > > > > > medianof3: func [a b c] [ > > > ewd/do [ > > > a > b [set [a b] reduce [b a]] > > > b > c [set [b c] reduce [c b]] > > > ] > > > b > > > ] > > > > > medianof3: func [a b c] [ > ewd/do [ > positive? a - b [set [a b] reduce [b a]] > positive? b - c [set [b c] reduce [c b]] > ] > b > ] > > and so on for the other examples... right? > > Hmmm... Those definitions for 'gt? 'eq? 'lt? (etc.) are looking > better all the time! > > -jn- >
