summaryrefslogtreecommitdiffstats
path: root/arith.c
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2014-11-20 20:23:17 -0800
committerKaz Kylheku <kaz@kylheku.com>2014-11-20 20:23:17 -0800
commit7320959c0a70a679011d0a0e0d2e43c586f631ab (patch)
tree86b5c0d459d96f055839e8feafee95ef053f047a /arith.c
parentd4b9a1e45899f86dbb9d5bef1f53fffa9dc05d44 (diff)
downloadtxr-7320959c0a70a679011d0a0e0d2e43c586f631ab.tar.gz
txr-7320959c0a70a679011d0a0e0d2e43c586f631ab.tar.bz2
txr-7320959c0a70a679011d0a0e0d2e43c586f631ab.zip
* arith.c (wrap_star, wrap): New functions.
* eval.c (eval_init): Registered wrap and wrap* intrinsics. * lib.h (wrap_star, wrap): Declared. * txr.1: wrap and wrap* documented.
Diffstat (limited to 'arith.c')
-rw-r--r--arith.c13
1 files changed, 13 insertions, 0 deletions
diff --git a/arith.c b/arith.c
index 23cf66a8..00621a5d 100644
--- a/arith.c
+++ b/arith.c
@@ -938,6 +938,19 @@ divzero:
uw_throw(numeric_error_s, lit("mod: division by zero"));
}
+val wrap_star(val start, val end, val num)
+{
+ val modulus = minus(end, start);
+ val num_off = minus(num, start);
+ val num_mod = mod(num_off, modulus);
+ return plus(start, num_mod);
+}
+
+val wrap(val start, val end, val num)
+{
+ return wrap_star(start, succ(end), num);
+}
+
static val to_float(val func, val num)
{
switch (type(num)) {