since we have real numbers now, I thought it could be interesting to implement Maclaurin series.
and that means we can have decently good sin(x), cos(x), e^(x) and so on.
https://en.wikipedia.org/wiki/Taylor_series
So, I wrote functions to implement factorial x! and conversion of degrees to radians and back.
Largest factorial we can do in TLISP is 12!=479,001,600
13! wraps back to a negative number.
Code: Select all
(setq we_deg2rad (lambda (d)
(block (output PI)
(setq PI 3.141592653589)
(setq output (* d (/ PI 180.0)))
output
)
))
(setq we_rad2deg (lambda (r)
(block (output PI)
(setq PI 3.141592653589)
(setq output (* r (/ 180.0 pi)))
output
)))
(setq we_factorial (lambda (imput)
(block (output tempNumber)
(setq tempNumber imput)
(setq output imput)
(switch
(eq imput 0)
(setq output 1)
(eq imput 1)
(setq output 1)
(loop (neq tempNumber 1)
(block Nil
(setq tempNumber (subtract tempNumber 1))
;(printTo 'console "tempNumber " tempNumber)
(setq output (multiply output tempNumber))
;(printTo 'console "output " output)
)
)
)
output
)))
Code: Select all
(setq we_sin (lambda (number precision)
;number is real
;precision MUST be an integer between 1 and 5
(block (output)
(setq output 0)
(setq number (we_deg2rad number))
(for i 0 precision
(block (index)
(setq index (+ (* 2 precision) 1))
(setq output (+ output (* (/ (pow -1 precision) (we_factorial index)) (pow number index))))
)
)
output
)))