Skip to content

Instantly share code, notes, and snippets.

@jocke-l
Last active December 15, 2015 11:59
Show Gist options
  • Save jocke-l/5257407 to your computer and use it in GitHub Desktop.
Save jocke-l/5257407 to your computer and use it in GitHub Desktop.
A function that computes π
import Data.Number.CReal
piit accuracy = showCReal 100 (go 1 (1 / sqrt 2) (1 / 4) 1)
where go a b t p | (a - b) >= accuracy = let aa = (a + b) / 2
bb = sqrt (a * b)
tt = t - p * (a - aa)^2
pp = 2 * p
in go aa bb tt pp
| otherwise = (a + b)^2 / (4 * t)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment