Skip to content

Instantly share code, notes, and snippets.

@eunomie
Last active February 26, 2016 06:22
Show Gist options
  • Save eunomie/bd4d8d491d686580167b to your computer and use it in GitHub Desktop.
Save eunomie/bd4d8d491d686580167b to your computer and use it in GitHub Desktop.
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