User:Spekkio: Difference between revisions
Content deleted Content added
No edit summary |
No edit summary |
||
Line 35:
<lang lisp>(defun pie() 31415926535897932384626433832795028841971693993751058209749/10000000000000000000000000000000000000000000000000000000000)
(defun factorial-rec (n)
(if (= n 0)
1
(* n (factorial-rec (- n 1)))))
(defun
(if (< n 2)
result
(factorial (- n 1) :result (* result n))))
(defun powint (a b &key (result 1))
(if (= b 0)
(if (> b 0)
(
)
)
Line 148 ⟶ 153:
(defun pown (a b) (powern a b))
(defun sinew(x &key (n 0) (prev 0))
(let ((cosn (* (/ (powint -1 n) (factorial (+ (* 2 n) 1)) ) (powint x (+ (* 2 n) 1)))
))
Line 154 ⟶ 159:
(progn
(float cosn)
(sinew x :n (1+ n) :prev (+ prev cosn))
)
(arithmetic-error (x) (+ prev cosn) ))
Line 160 ⟶ 165:
)
(defun sine(x) (
(defun cosinew(x &key (n 0) (prev 0))
(let ((cosn (* (/ (powint -1 n) (factorial (* 2 n))) (powint x (* 2 n)))))
(handler-case
(progn
(float cosn)
(cosinew x :n (1+ n) :prev (+ prev cosn))
)
(arithmetic-error (x) (+ prev cosn) ))
Line 173 ⟶ 178:
)
(defun cosine(x) (cosinew x
(defun tang(x) (/ (sine x) (cosine x)))
(defun asinew(x &key (n 0) (prev 0))
(let ((cosn (/ (* (factorial (* 2 n)) (powint x (+ (* 2 n) 1))) (* (powint 4 n) (powint (factorial n) 2) (+ (* 2 n) 1)))
))
Line 183 ⟶ 188:
(progn
(float cosn)
(asinew x :n (1+ n) :prev (+ prev cosn))
)
(arithmetic-error (x) prev ))
)
)
(defun asinew2(x)
(let ((n 0))
(let ((next 0))
(loop while (handler-case (float next) (arithmetic-error (err) NIL)) do
(progn
(setq next (+ (/ (* (factorial (* 2 n)) (powint x (+ (* 2 n) 1))) (* (powint 4 n) (powint (factorial n) 2) (+ (* 2 n) 1))) next))
(setq n (+ n 1))
)
)
)))
(defun asine (x)
(if (< x 1)
(if (> x -1)
(asinew x
(/ (pie) -2)
)
Line 210 ⟶ 228:
(+ (fibrec (- n 1)) (fibrec (- n 2))))))
(defun test() (let ((n 0)) (loop while (< n 10) collect n do (if (= (float (sine n)) (sin n)) () (progn (write n) (write (terpri)) (write (sin n)) (write (terpri)) (write (float (sine n))) (write (terpri)) )) (setq n (+ n 1/10)))))</lang>
test:
|