Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (* sin approx *)
- let sin (x : float):float =
- let nth (n: float) (x : float) : float = (* gives nth element for fiven x *)
- let rec fact (x:float) : float =
- if x = 0.0 then 1.0
- else x *. (fact(x -. 1.0)) in
- (-1.0)**(n +. 1.0) *. x**(2.0*.n -. 1.0) /. fact (2.0*.n -. 1.0) in
- let rec sin_tay (acc:float) (element:float) : float =
- let new_acc : float = acc +. nth element x in
- if new_acc <> acc (*stop on precision error*)
- then sin_tay new_acc (element +. 1.0)
- else new_acc
- in
- sin_tay 0.0 1.0;; (*intitial value of acc = 0, starting from first element*)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement