diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2015-01-12 22:49:37 -0800 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2015-01-12 22:49:37 -0800 |
commit | d91ed5da5a5ea74308ad78faec31e03c48b7e767 (patch) | |
tree | dc3ce8949503ce1acf4817ea3d941b4dfc5366bc /arith.c | |
parent | 0343c6f32c5bd8335e88595cb9d23506625b2586 (diff) | |
download | txr-d91ed5da5a5ea74308ad78faec31e03c48b7e767.tar.gz txr-d91ed5da5a5ea74308ad78faec31e03c48b7e767.tar.bz2 txr-d91ed5da5a5ea74308ad78faec31e03c48b7e767.zip |
* arith.c (zerop): Handle character arguments.
(plusp, minusp): New functions.
* eval.c (eval_init): Register plusp and minusp.
* lib.h (plusp, minusp): Declared.
* txr.1: Documented plusp and minusp, and the
handling of characters by zerop.
Diffstat (limited to 'arith.c')
-rw-r--r-- | arith.c | 34 |
1 files changed, 34 insertions, 0 deletions
@@ -993,11 +993,45 @@ val zerop(val num) return nil; case FLNUM: return if2(c_flo(num) == 0.0, t); + case CHR: + return if2(num == chr(0), t); default: uw_throwf(error_s, lit("zerop: ~s is not a number"), num, nao); } } +val plusp(val num) +{ + switch (type(num)) { + case NUM: + return if2(c_num(num) > 0, t); + case BGNUM: + return if2(mp_cmp_z(mp(num)) == MP_GT, t); + case FLNUM: + return if2(c_flo(num) > 0.0, t); + case CHR: + return if2(num != chr(0), t); + default: + uw_throwf(error_s, lit("plusp: ~s is not a number"), num, nao); + } +} + +val minusp(val num) +{ + switch (type(num)) { + case NUM: + return if2(c_num(num) < 0, t); + case BGNUM: + return if2(mp_cmp_z(mp(num)) == MP_LT, t); + case FLNUM: + return if2(c_flo(num) < 0.0, t); + case CHR: + return nil; + default: + uw_throwf(error_s, lit("minusp: ~s is not a number"), num, nao); + } +} + val evenp(val num) { switch (type(num)) { |