[Haskell-cafe] Monte Carlo Pi calculation (newbie learnings)

ajb at spamcop.net ajb at spamcop.net
Mon Nov 5 18:55:37 EST 2007

G'day all.

Quoting Don Stewart <dons at galois.com>:

>     calculatePi total g = fromIntegral (4*count) / fromIntegral total

This is slightly more robust in cases where the multiplication would
overflow an Int:

     calculatePi total g
         = fromRational ((4*fromIntegral count) % fromIntegral total)

Andrew Bromage

More information about the Haskell-Cafe mailing list