[REBOL] Re: Math (division)
From: larry:ecotope at: 30-May-2001 21:34
Hi all
Actually there is a flaw in the implementation of the REBOL comparison
operators (=, >=, <=, equal?, greater?, lesser?, etc.) when applied to the
decimal! type. To be sure the math-int function works correctly for ALL
cases, it should be changed to:
math-int: func [x [number!]][ zero? x // 1]
An example of the problem:
>> math-int 1e-20
== false
which is correct. The function below using equal will return true which is
not correct. One manifestation of the flaw is:
>> 0 = 1e-20
== true
>> positive? 1e-20 - 0
== true
>> zero? 1e-20
== false
>>
The functions zero? positive? and negative? work correctly for the decimal!
type, but = gives an incorrect answer.
-Larry
----- Original Message -----
From: "Larry Palmiter" <[larry--ecotope--com]>
To: <[rebol-list--rebol--com]>
Sent: Wednesday, May 30, 2001 7:38 PM
Subject: [REBOL] Re: Math (division)
Hi Ammon
If you just want to know if it is a REBOL integer:
integer? x
If you want to know if a number has no digits after the decimal place (i.e.,
it is an integer in the mathematical sense), regardless of its REBOL type:
>> math-int: func [x [number!]][x // 1 = 0]
>> math-int pi
== false
>> x: to-decimal 2
== 2
>> type? x
== decimal!
>> math-int x
== true
>> type? 2 ** 52
== decimal!
>> math-int 2 ** 52
== true
>> math-int -2 ** 52
== true
HTH
-Larry