From 545f3a7a3e148324981c7a3bffff8045ec60ea05 Mon Sep 17 00:00:00 2001 From: Preston Pan Date: Mon, 9 Jan 2023 23:05:10 -0800 Subject: add exp function --- stdlib/math.nxs | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) (limited to 'stdlib/math.nxs') 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))) -- cgit