(fromRational (1%5)) :: Double

S.D.Mechveliani mechvel@math.botik.ru
Thu, 19 Apr 2001 10:02:34 +0400

Lennart Augustsson <lennart@mail.augustsson.net> writes

> "S.D.Mechveliani" wrote:

>> the matter is in what the _language standard_ says.
>> If it puts that `0.9' in the user program means precizely  9%10,
>> then Lennart is right.

> I quote the report:
> "The floating point literal f is equivalent to 
> fromRational (n Ratio.% d), where fromRational is a
> method in class Fractional and Ratio.% constructs a rational from
> two integers, as defined in the Ratio library. The integers n and 
> d are chosen so that n/d = f."
> I think the way Haskell handles numeric literals is pretty nice and
> it's important to understand what happens if you use them. :)

I confess, I do not understand from the previous letters, in what way,
for example, Hugs finds
                        Prelude> (fromRational (1%5)) :: Double


I never dealt with Floats in Haskell. And thought that a value of 
Double  has mantissa in a binary representation. So, the interpreter 
has to convert a decimal 5 to a binary 101B, evaluate  1B / 101B  
obtaining an infinite sequence of binary digits and take the first  m
of them required for Double. 
Printing the result should yield something like  0.1999...

Thank you in advance for the explanation. 

Serge Mechveliani