diff options
author | Preston Pan <preston@nullring.xyz> | 2023-01-09 23:05:10 -0800 |
---|---|---|
committer | Preston Pan <preston@nullring.xyz> | 2023-01-09 23:05:10 -0800 |
commit | 545f3a7a3e148324981c7a3bffff8045ec60ea05 (patch) | |
tree | bbd8f1ce1a656047139efcf1a073220546d0dfd7 /stdlib/math.nxs | |
parent | 43f11a93385c4848bfad49510bdea2849f241816 (diff) |
add exp function
Diffstat (limited to 'stdlib/math.nxs')
-rw-r--r-- | stdlib/math.nxs | 24 |
1 files changed, 19 insertions, 5 deletions
diff --git a/stdlib/math.nxs b/stdlib/math.nxs index f913d82..77ffc7f 100644 --- a/stdlib/math.nxs +++ b/stdlib/math.nxs @@ -3,18 +3,32 @@ (bind powi (lambda (x y) (if (= y 1) x - (* x (pow x (- y 1))) -))) + (* x (powi x (- y 1))) + ) +)) + +(bind inv (lambda (x) (/ 1.0 x))) + (bind factorial (lambda (n) - (if (= n 0) 1 (* n (factorial (print(- n 1))))))) + (if (= n 0) 1 (* n (factorial (- n 1)))))) ;; complicated functions -(bind exp (lambda (x) x)) +(bind expr (lambda (x y) + (if (<= y 0) + 1 + (+ (/ (powi x y) (factorial y)) (expr x (- y 1))) + ) +)) -(bind ln (lambda (x) x)) +(bind exp (lambda (x) + (expr x 13) +)) (bind sin (lambda (x) x)) (bind cos (lambda (x) x)) (bind tan (lambda (x) (/ (sin x) (cos x)))) + +(print (exp 1.0)) +;(print (ln (exp 1))) |