aboutsummaryrefslogtreecommitdiff
path: root/tests/math.lisp
diff options
context:
space:
mode:
authorMistivia <i@mistivia.com>2025-06-22 17:23:32 +0800
committerMistivia <i@mistivia.com>2025-06-22 17:23:49 +0800
commit47c8353366c5cd7544d182a897bacaa303c08d8e (patch)
treed5362488aae5baba2afc3884d5339a09f182eaf9 /tests/math.lisp
parent5c0eddbed7f838daac17e0b9d9c2a23f17da4660 (diff)
math functions
Diffstat (limited to 'tests/math.lisp')
-rw-r--r--tests/math.lisp86
1 files changed, 86 insertions, 0 deletions
diff --git a/tests/math.lisp b/tests/math.lisp
new file mode 100644
index 0000000..53e4668
--- /dev/null
+++ b/tests/math.lisp
@@ -0,0 +1,86 @@
+(defun ~~ (a b)
+ (if (< (abs (- a b)) 0.01)
+ nil
+ (error "failed")))
+
+(assert (= 1 (abs -1)))
+(assert (= 1.1 (abs -1.1)))
+(assert (= 1 (abs 1)))
+(assert (= 1.1 (abs 1.1)))
+
+(~~ 3.141 pi)
+(assert-error (~~ 3.2 pi))
+
+(~~ 2.718 e)
+
+(assert (= 1.0 (float 1)))
+(assert (= -1.0 (float -1)))
+
+(~~ 8 (pow 2 3))
+(~~ 1.414 (pow 2 0.5))
+(~~ 1.732 (pow 3 0.5))
+
+(~~ 2.0 (floor 2.1))
+(~~ 2.0 (floor 2.5))
+(~~ 2.0 (floor 2.7))
+(~~ -2.0 (floor -1.1))
+(~~ -2.0 (floor -1.5))
+(~~ -2.0 (floor -1.7))
+
+(~~ 2.0 (truncate 2.1))
+(~~ 2.0 (truncate 2.5))
+(~~ 2.0 (truncate 2.7))
+(~~ -2.0 (truncate -2.1))
+(~~ -2.0 (truncate -2.5))
+(~~ -2.0 (truncate -2.7))
+
+(~~ 2.0 (ceiling 1.1))
+(~~ 2.0 (ceiling 1.5))
+(~~ 2.0 (ceiling 1.7))
+(~~ -2.0 (ceiling -2.1))
+(~~ -2.0 (ceiling -2.5))
+(~~ -2.0 (ceiling -2.7))
+
+(~~ 2.0 (round 2.1))
+(~~ 2.0 (round 1.5))
+(~~ 2.0 (round 1.7))
+(~~ -2.0 (round -2.1))
+(~~ -2.0 (round -1.5))
+(~~ -2.0 (round -1.7))
+
+(~~ 0 (sin 0))
+(~~ 1 (sin (/ pi 2)))
+(~~ -1 (sin (- (/ pi 2))))
+
+(~~ 1 (cos 0))
+(~~ 0 (cos (/ pi 2)))
+(~~ 0 (cos (- (/ pi 2))))
+
+(~~ (tan 1.1234) (/ (sin 1.1234) (cos 1.1234)))
+
+(~~ (asin 0.5) 0.525)
+(~~ (acos 0.5) 1.047)
+(~~ (atan 0.5) 0.463)
+
+(~~ 0 (ln 1))
+(~~ 1 (ln e))
+(~~ 2 (ln (* e e)))
+(~~ 1.5 (ln (* e (sqrt e))))
+(~~ 1.333 (ln (* e (cbrt e))))
+(~~ 0.667 (ln (/ e (cbrt e))))
+
+(~~ 0 (log10 1))
+(~~ 1 (log10 10))
+(~~ 2 (log10 (* 10 10)))
+(~~ 1.5 (log10 (* 10 (sqrt 10))))
+(~~ 1.333 (log10 (* 10 (cbrt 10))))
+(~~ 0.667 (log10 (/ 10 (cbrt 10))))
+
+(~~ 0 (log2 1))
+(~~ 1 (log2 2))
+(~~ 2 (log2 (* 2 2)))
+(~~ 1.5 (log2 (* 2 (sqrt 2))))
+(~~ 1.333 (log2 (* 2 (cbrt 2))))
+(~~ 0.667 (log2 (/ 2 (cbrt 2))))
+
+(~~ (pow e 1.5) (exp 1.5))