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
"S.D.Mechveliani" wrote:
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.
What are you talking about? Input in decimal representation is stored as a Rational number. There is absolutely no loss of precision. -- Lennart
Lennart Augustsson wrote:
"S.D.Mechveliani" wrote: ... ...
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.
What are you talking about? Input in decimal representation is stored as a Rational number. There is absolutely no loss of precision.
No need for whatareyoutalkingabout preamble. Input in decimal representation *in general* is stored as the implementors wish. You can't a priori know all, if you are far from the implementors, and if the relevant documentation is hard to find... How many people on this mailing list are really au courant? I had a few weeks ago a very nasty surprise: the "educational variant/teaching language" of Rice DrScheme stores a decimal constant as an EXACT number, and the "full language" as a floating INEXACT. For two days I thought that the function 'floor' is buggy. Jerzy Karczmarczuk Caen, France
Jerzy Karczmarczuk wrote:
Lennart Augustsson wrote:
"S.D.Mechveliani" wrote: ... ...
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.
What are you talking about? Input in decimal representation is stored as a Rational number. There is absolutely no loss of precision.
No need for whatareyoutalkingabout preamble. Input in decimal representation *in general* is stored as the implementors wish. You can't a priori know all, if you are far from the implementors, and if the relevant documentation is hard to find... How many people on this mailing list are really au courant?
I apologize for the preamble. But the Haskell spec still clearly specifies that numeric literals are "stored" as Integer if they lack a decimal point and Rational otherwise. And the fromInteger/fromRational is applied to this. For Haskell there is no implementors choice if you want to obey the report. -- Lennart
participants (3)
-
Jerzy Karczmarczuk -
Lennart Augustsson -
S.D.Mechveliani