Re: [Haskell-cafe] double2Float is faster than (fromRational . toRational)

2010-05-27 Thread Bulat Ziganshin
Hello Daniel, Friday, May 21, 2010, 11:55:35 PM, you wrote: > xf = (fromRational $ toRational xd) :: Float > xf = double2Float xd > am still surprised how often such kinds of unobvious problems occur > while programming in Haskell does it mean that all other languages you are used doesn't have

Re: [Haskell-cafe] double2Float is faster than (fromRational . toRational)

2010-05-23 Thread Daniel Fischer
On Sunday 23 May 2010 13:12:16, wren ng thornton wrote: > Daniel Fischer wrote: > > There are more rules elsewhere. If you compile with optimisations, GHC > > turns your realToFrac into double2Float# nicely, so it's okay to use > > realToFrac. > > However, without optimisations, no rules fire, so y

Re: [Haskell-cafe] double2Float is faster than (fromRational . toRational)

2010-05-23 Thread wren ng thornton
Daniel Fischer wrote: There are more rules elsewhere. If you compile with optimisations, GHC turns your realToFrac into double2Float# nicely, so it's okay to use realToFrac. However, without optimisations, no rules fire, so you'll get (fromRational . toRational). That must be new, because it

Re: [Haskell-cafe] double2Float is faster than (fromRational . toRational)

2010-05-21 Thread Pierre-Etienne Meunier
By the way, speaking of floating-point precision, is there a real reason why haskell forces us to write : foreign import ccall unsafe "math.h frexp" c_frexp::CDouble->(Ptr CInt)->IO () foreign import ccall unsafe "math.h ldexp" c_ldexp::CDouble->CInt->IO CDouble ulp::Double->Double ulp x=unsafeP

Re: [Haskell-cafe] double2Float is faster than (fromRational . toRational)

2010-05-21 Thread Don Stewart
dvde: > Dear Haskellers, > > I just want to share an observation. I had to convert a Double to a > Float value in an inner loop of an application, and I used somethin like > this: > > xf = (fromRational $ toRational xd) :: Float > > The program works on windows but it did not on OSX - it was to

Re: [Haskell-cafe] double2Float is faster than (fromRational . toRational)

2010-05-21 Thread Daniel Fischer
On Friday 21 May 2010 22:06:43, Henning Thielemann wrote: > On Fri, 21 May 2010, Daniel van den Eijkel wrote: > > Dear Haskellers, > > > > I just want to share an observation. I had to convert a Double to a > > Float value in an inner loop of an application, and I used somethin > > like this: > > >

Re: [Haskell-cafe] double2Float is faster than (fromRational . toRational)

2010-05-21 Thread Daniel van den Eijkel
I see. And I changed the code, it works well. Thanks for that! Daniel Henning Thielemann schrieb: On Fri, 21 May 2010, Daniel van den Eijkel wrote: Dear Haskellers, I just want to share an observation. I had to convert a Double to a Float value in an inner loop of an application, and I use

Re: [Haskell-cafe] double2Float is faster than (fromRational . toRational)

2010-05-21 Thread Henning Thielemann
On Fri, 21 May 2010, Daniel van den Eijkel wrote: Dear Haskellers, I just want to share an observation. I had to convert a Double to a Float value in an inner loop of an application, and I used somethin like this: xf = (fromRational $ toRational xd) :: Float I think realToFrac is the func

[Haskell-cafe] double2Float is faster than (fromRational . toRational)

2010-05-21 Thread Daniel van den Eijkel
Dear Haskellers, I just want to share an observation. I had to convert a Double to a Float value in an inner loop of an application, and I used somethin like this: xf = (fromRational $ toRational xd) :: Float The program works on windows but it did not on OSX - it was too slow. Now, after b