diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2011-12-13 19:37:19 -0800 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2011-12-13 19:37:19 -0800 |
commit | 64b06932ed7d8dd8c904e66a70a53ae4c8ec4448 (patch) | |
tree | 643059d8904fda99b240ae6756100943a7a1c3e5 /arith.c | |
parent | ef47dfe4fcb7c1be369ae83221386b9da6474a1e (diff) | |
download | txr-64b06932ed7d8dd8c904e66a70a53ae4c8ec4448.tar.gz txr-64b06932ed7d8dd8c904e66a70a53ae4c8ec4448.tar.bz2 txr-64b06932ed7d8dd8c904e66a70a53ae4c8ec4448.zip |
* arith.c (evenp, oddp): New functions.
* eval.c (eval_init): New functions registered as intrinsics.
* lib.h (evenp, oddp): Declared.
* txr.1: Documentation stub updated.
Diffstat (limited to 'arith.c')
-rw-r--r-- | arith.c | 30 |
1 files changed, 30 insertions, 0 deletions
@@ -711,6 +711,36 @@ val zerop(val num) return nil; } +val evenp(val num) +{ + switch (tag(num)) { + case TAG_NUM: + return (c_num(num) % 2 == 0) ? t : nil; + case TAG_PTR: + if (num->t.type == BGNUM) + return mp_iseven(mp(num)) ? t : nil; + /* fallthrough */ + default: + uw_throwf(error_s, lit("evenp: ~s is not a number"), num, nao); + return nil; + } +} + +val oddp(val num) +{ + switch (tag(num)) { + case TAG_NUM: + return (c_num(num) % 2 != 0) ? t : nil; + case TAG_PTR: + if (num->t.type == BGNUM) + return mp_isodd(mp(num)) ? t : nil; + /* fallthrough */ + default: + uw_throwf(error_s, lit("oddp: ~s is not a number"), num, nao); + return nil; + } +} + val gt(val anum, val bnum) { int tag_a = tag(anum); |