[Haskell-cafe] about integer and float operations
Manlio Perillo
manlio_perillo at libero.it
Wed Feb 4 17:03:15 EST 2009
Max Rabkin ha scritto:
> [...]
>
> Then we can define
> (/.) :: (Real a1, Real a2, Fractional a) => a1 -> a2 -> a
> x /. y = fromRational $ toRational x / toRational y
> [...]
>
> (//) :: (Integral b, Real a, Real a1) => a -> a1 -> b
> x // y = floor $ toRational x / toRational y
>
> Hope that helps,
> Max
>
Yes, thanks.
However there is still a *big* problem: it is inefficient.
Here is a Python version of the Chudnovsky algorithm [1] for computing Pi:
http://paste.pocoo.org/show/102800/
On my system it takes 10 seconds.
Here is an Haskell version:
http://paste.pocoo.org/show/102801/
On my system it takes 30 seconds.
Thanks Manlio Perillo
[1]
http://upload.wikimedia.org/math/6/6/8/6681cd21f3ca9bf13248a87d4202e06a.png
More information about the Haskell-Cafe
mailing list