User:Spekkio: Difference between revisions

no edit summary
No edit summary
No edit summary
 
(7 intermediate revisions by the same user not shown)
Line 2:
{{mylang|C|Active}}
{{mylang|C++|Beginner}}
{{mylang|GLSL|Beginner}}
{{mylang|Java|Active}}
{{mylang|JavaScript|Active}}
Line 15 ⟶ 16:
{{mylang|VHDL|Rusty}}
{{mylangend}}
 
 
Hello! I'm a Electronic Engineer, working with electronics developement.
 
 
I love computer programming, and my hobby is to program small simple computer programs.
 
I usually get stuck on an idea that I think would be fun to try and solve.
 
I love learning new programming languages.
 
Found this page recently, and it is perfect for me. :D
 
 
Currently I'm working on Huffman coding in C, and implementing a multi precision library to calculate
 
maclaurin series for different functions sin/cos/sqrt/pow etc... (see my recent post in [[Talk:Nth root]])
 
<lang lisp>(defun pie() 31415926535897932384626433832795028841971693993751058209749/10000000000000000000000000000000000000000000000000000000000)
 
(defun factorial-rec (n)
(if (= n 0)
1
(* n (factorial-rec (- n 1)))))
 
(defun factorial (n &key (result 1))
(if (< n 2)
result
(factorial (- n 1) :result (* result n))))
 
(defun powint (a b &key (result 1))
(if (= b 0)
1result
(if (> b 0)
(* a (powint a (- b 1) :result (* result a))
(*powint a (/+ 1b a1) :result (powint* aresult (+ b/ 1 a)))
)
)
Line 148 ⟶ 137:
(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 ⟶ 143:
(progn
(float cosn)
(sinew x :n (1+ n) :prev (+ prev cosn))
)
(arithmetic-error (x) (+ prev cosn) ))
Line 160 ⟶ 149:
)
 
(defun sine(x) (sinewif (= x 0) 0 (sinew 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 ⟶ 162:
)
 
(defun cosine(x) (cosinew x 0 0))
 
(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 ⟶ 172:
(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 0 0)
(/ (pie) -2)
)
Line 200 ⟶ 202:
 
(defun fibcalc (n)
(let ((sqrtFive (sqrtnsquareroot 5)))
(/ (- (powint (* 1/2 (+ 1 sqrtFive)) n) (powint (* 1/2 (- 1 sqrtFive)) n)) sqrtFive)))
 
Line 210 ⟶ 212:
(+ (fibrec (- n 1)) (fibrec (- n 2))))))
 
</lang>
 
(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:
 
test:
[14]> (float (asine 9/100))
Line 237 ⟶ 239:
[15]> (float (squareroot 1/2))
0.70710677
[15]> (= (float (squareroot 1/2) 1.0) (*float (sine (* 45 (/ (* 2 (pie)) 360) ))))
T
[15]> (= (sine (* 45 (/ (* 2 (pie)) 360) )) (sine (/ (pie) 4)))
T
[15]> (= (cosine (/ (pie) 4)) (sine (/ (pie) 4)))
NIL
[15]> (= (float (cosine (/ (pie) 4))) (float (sine (/ (pie) 4))))
T
Anonymous user