diff options
author | Leah Neukirchen <leah@vuxu.org> | 2022-12-09 17:51:21 +0100 |
---|---|---|
committer | Leah Neukirchen <leah@vuxu.org> | 2022-12-09 17:51:21 +0100 |
commit | 0c5dec75a7c68ca69384bbc27f8a273976de92d1 (patch) | |
tree | 1f8735b20005b1c4832180310bb93c1e1f64ea01 | |
parent | a1ef85b5fab8dea3f9d2144102079de198d8ee3e (diff) | |
download | mew-0c5dec75a7c68ca69384bbc27f8a273976de92d1.tar.gz mew-0c5dec75a7c68ca69384bbc27f8a273976de92d1.tar.xz mew-0c5dec75a7c68ca69384bbc27f8a273976de92d1.zip |
add sgn
-rw-r--r-- | mew.scm | 6 | ||||
-rw-r--r-- | mew.svnwiki | 4 | ||||
-rw-r--r-- | tests/test.mew | 7 |
3 files changed, 16 insertions, 1 deletions
diff --git a/mew.scm b/mew.scm index a6ac371..f95c0b1 100644 --- a/mew.scm +++ b/mew.scm @@ -18,7 +18,7 @@ odometer one-of op op* per prn proj puts rand range rep - sample scan scan-right sing? search seq set set-at + sample scan scan-right sing? search seq set set-at sgn shuffle shuffle! str slurp tally-accumulator tbl time while @@ -105,6 +105,10 @@ (reexport err) + (define (sgn n) + (cond ((< n 0) -1) + ((> n 0) 1) + (else 0))) ; always return an integer 0, not n (define (inc i) (+ i 1)) diff --git a/mew.svnwiki b/mew.svnwiki index 29eb4e9..11a2669 100644 --- a/mew.svnwiki +++ b/mew.svnwiki @@ -152,6 +152,10 @@ Alias for {{floor-quotient}}. Alias for {{floor-remainder}}. +<procedure>(sgn <num>)</procedure> + +Returns -1, 0, 1 depending on whether {{<num>}} is negative, zero, or positve. + == General helpers diff --git a/tests/test.mew b/tests/test.mew index 1fe7ec1..72d1e27 100644 --- a/tests/test.mew +++ b/tests/test.mew @@ -83,6 +83,13 @@ (test 5 (mod -16 7)) (test -2 (mod -16 -7))) +(test-group "sgn" + (test -1 (sgn -42)) + (test 0 (sgn 0)) + (test #t (eq? 0 (sgn 0.0))) + (test #t (eq? 0 (sgn -0.0))) + (test 1 (sgn 42))) + (test-group "inc" (test 6 (inc 5)) (test 0 (inc -1)) |