Last active
February 26, 2016 06:22
-
-
Save eunomie/bd4d8d491d686580167b to your computer and use it in GitHub Desktop.
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 List exposing (sum, map, foldl) | |
pow : Float -> Float -> Float | |
pow num p = | |
if p == 0 then | |
1 | |
else if p > 0 then | |
num * (pow num (p - 1)) | |
else | |
1 / num * (pow num (p + 1)) | |
fact : Float -> Float | |
fact x = if x <= 0 then 1 else x * fact(x - 1) | |
sine : Float -> Float | |
sine x = | |
sum (map (\i -> (pow -1 i) * (pow x (i * 2 + 1)) / (fact (i * 2 + 1))) [0..9]) | |
sinefold : Float -> Float | |
sinefold x = | |
foldl (\i sum -> sum + (pow -1 i) * (pow x (i * 2 + 1)) / (fact (i * 2 + 1))) 0 [0..9] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment