summaryrefslogtreecommitdiff
path: root/stdlib/math.nxs
diff options
context:
space:
mode:
Diffstat (limited to 'stdlib/math.nxs')
-rw-r--r--stdlib/math.nxs24
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)))