[Haskell-cafe] Re: Very fast loops. Now!

Bryan O'Sullivan bos at serpentine.com
Mon Feb 12 17:25:21 EST 2007


David Roundy wrote:

> I'm rather curious (if you're sill interested) how this'll be affected by
> the removal of the division from the inner loop. e.g.
> 
>     go :: Double -> Double -> Int -> IO ()
>     go !x !y !i
>         | i == 1000000000 = printf "%.6f\n" (x+y)
>         | otherwise       = go (x*y*(1.0/3)) (x*9) (i+1)
> 
> 
>     for (; i<1000000000; i++) {
>         x = x*y*(1.0/3.0);
>         y = x*9.0;
>     }

GCC will do the transformation itself if you use -ffast-math.  It 
requires the flag as the results aren't exactly numerically equivalent.

	<b


More information about the Haskell-Cafe mailing list