Skip to content

Instantly share code, notes, and snippets.

@yaraki
Created July 7, 2015 08:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yaraki/55dc19bb2a881358ba7c to your computer and use it in GitHub Desktop.
Save yaraki/55dc19bb2a881358ba7c to your computer and use it in GitHub Desktop.
Simple sine calculation by taylor expansion
(defconst if3 (* 2 3))
(defconst if5 (* if3 4 5))
(defconst if7 (* if5 6 7))
(defconst if9 (* if7 8 9))
(defconst if11 (* if9 10 11))
(defun simple-sine (x)
(unless (eq 'float (type-of x))
(setf x (float x)))
(let* ((x2 (* x x))
(x3 (* x2 x))
(x5 (* x3 x2))
(x7 (* x5 x2))
(x9 (* x7 x2))
(x11 (* x9 x2)))
(+ x
(- (/ x3 if3))
(/ x5 if5)
(- (/ x7 if7))
(/ x9 if9)
(- (/ x11 if11)))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment