Last active
December 14, 2018 23:39
-
-
Save brunoczim/173fefc6f11e0013293777f8e96918fb to your computer and use it in GitHub Desktop.
Euler and Golden Ratio Approximation in Haskell
This file contains hidden or 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 Approx where | |
approxGolden :: Int -> Double | |
approxGolden n = approx n 1 1 | |
where | |
approx 0 p q = q / p | |
approx n p q = approx (n - 1) q (p + q) | |
golden :: Double | |
golden = approxGolden 64 | |
approxEuler :: Int -> Double | |
approxEuler n = approx 0 1 0 where | |
approx m a r = if m == n | |
then r | |
else approx (m + 1) a' r' | |
where | |
a' = (fromInteger . toInteger) (m + 1) * a | |
r' = r + (1 / a) | |
euler :: Double | |
euler = approxEuler 64 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment