Last active
December 28, 2015 12:09
-
-
Save EnricoMiccoli/b0dd52eb1d0e756cd281 to your computer and use it in GitHub Desktop.
Approximates pi using Archimedes' method
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
module Pigrec where | |
pigrec :: Int -> Float | |
pigrec x = foldl (ptwon) (2 * sqrt 2) (map (\x -> 2^x) [2..x]) | |
ptwon :: Double -> Int -> Double | |
-- Given the perimeter pn of a n-sided polygon inscribed in a | |
-- circle of diameter 1 returns the perimeter of the 2n-sided | |
-- polygon inscribed in the same circle | |
ptwon pn n = n' * ( sqrt (1 + l) - sqrt (1 - l)) | |
where | |
n' = fromIntegral n | |
l = pn / n' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment