toRational (0.9). Reply

S.D.Mechveliani mechvel@math.botik.ru
Wed, 18 Apr 2001 10:47:13 +0400


People wrote about   toRational (0.9) == 9%10  = False 
                     ...
Probably, the source of a `bug' is a language agreement that the 
input is in decimal representation (`0.9') and its meaning is a 
floating approximation in _binary_ representation.
For example,  1%5  yields a finite mantissa in decimal representation 
and an infinite (periodic) mantissa for the binary representation of  
toBinary(1%5) = 1B % 1001B.
Therefore applying toRational to any finite float approximation 
(Double, or other) of 1%5 does not return 1%5.

- ?

-----------------
Serge Mechveliani
mechvel@botik.ru