Last active
December 15, 2015 11:59
-
-
Save jocke-l/5257407 to your computer and use it in GitHub Desktop.
A function that computes π
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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