Hi folks,
Over the weekend I was playing with the REBOL money! datatype and discovered
some problems. Using the REBOL/Core console:
>> x: $10
== $10.00
>> y: x + .01
== $10.01
>> y - x
== $0.00 ;surprising result, displayed value is not correctly
rounded
We can check what is happening by retreiving the decimal value from the
money values:
>> dx: second x
== 10
>> dy: second y
== 10.01
>> dy - dx
== 9.99999999999979E-3 ;this is the actual numeric value of y - x, it
should round to .01
The problem seems to be incorrect or absent rounding of the difference:
>> to-money dy - dx
== $0.00
Checking when to-money will return .01 vs .00:
>> a: to-money "9.99999999999999934E-3"
== $0.00
>> b: to-money "9.99999999999999935E-3"
== $0.01
Clearly both of these values should round to $.01.
There some other anomalies also:
>> (y - x) * 1.00000000000001
== $0.00
>> (y - x) * 1.0000000000001
== $0.01
>> (y - x) * 10 ;displayed result is wrong by a factor of ten
== $0.01
>> (y - x) * 100 ;displayed result is correct
== $1.00
These problems are not due to the round-off intrinsic to decimal values.
Even in the worst case we have 15 significant digits of precision. The
example shows incorrect rounding in the 4th significant digit.
I wonder whether others have noticed this problem?
Note: this has been CC'd to feedback as a bug.
Cheers
Larry