RE: Floats and Doubles

2002-11-13 Thread Simon Marlow
> But this brings up a strange thing in GHCi. Suppose I load > the following module into GHCi: > > \begin{code} > module Foo where > > kalle = (fromRational ((toRational 4) - ( toRational 5.2 ))) > > default (Rational) > \end{code} > > What happens is the following: > > Prelude> :l Foo.hs >

Re: Floats and Doubles

2002-11-13 Thread Josef Svenningsson
On Wed, 13 Nov 2002, Jan Kort wrote: > > Juan Ignacio Garcia Garcia wrote: > > *P2> (fromRational ((toRational 4) - ( toRational 5.2 ))) > > -1.2002 > > I can't explain this one, how would fromRational > know that it has to create a Double ? > It's the defaulting mechanism that kicks i

Re: Floats and Doubles

2002-11-13 Thread Jan Kort
Juan Ignacio Garcia Garcia wrote: > *P2> (fromRational ((toRational 4) - ( toRational 5.2 ))) > -1.2002 I can't explain this one, how would fromRational know that it has to create a Double ? Jan ___ Glasgow-haskell-users mailing list [EMA

Re: Floats and Doubles

2002-11-12 Thread Seth Kurtzberg
If that is a serious question, then the answer is that if you want to take advantage of floating point hardware you are in general limited to those representations that the hardware understands. Also, most floating point representations have a binary field for what is effectively the significan

Re: Floats and Doubles

2002-11-12 Thread Jerzy Karczmarczuk
Lennart Augustsson wrote: > The number 5.2 is stored as a slightly different number as a Float, but the toRational function is exact so it gives you the number corresponding to the internal representation. Take a course on numerical analysis. :) Nope. Take a course entitled: Why all you zomb

Re: Floats and Doubles

2002-11-12 Thread Lennart Augustsson
Yes, they all seem to be right. You get these funny effects because numbers like 5.2 do not have an exact representation with floating point numbers in base to (like Float and Double most likely have on your machine). The number 5.2 is stored as a slightly different number as a Float, but the toRa

RE: Floats and Doubles

2002-11-12 Thread Simon Marlow
> I have been using some of the functions of the classes Real and > Fractional and I have observed that with the funcion > "toRational" we can > obtain the fraction that represents a given number. For instance: > *P2> toRational (5.2::Float) > 5452595 % 1048576 > Why we obtain this numbers inst