From dae9271da2babb8879c03946f106c64f2538ceb8 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Thu, 13 Dec 2018 06:28:50 -0800 Subject: nzerop: new function. * arith.c (nzerop): New function. * eval.c (eval_init): Register nzerop intrinsic. * lib.h (nzerop): Declared. * txr.1: Documented. --- arith.c | 22 ++++++++++++++++++++++ eval.c | 1 + lib.h | 1 + txr.1 | 25 ++++++++++++++++++++++++- 4 files changed, 48 insertions(+), 1 deletion(-) diff --git a/arith.c b/arith.c index 084d8cf5..67fa75c2 100644 --- a/arith.c +++ b/arith.c @@ -1557,6 +1557,28 @@ val zerop(val num) } } +val nzerop(val num) +{ + val self = lit("nzerop"); + + if (num == zero) + return nil; + + switch (type(num)) { + case NUM: + case BGNUM: + return t; + case FLNUM: + return tnil(c_flo(num, self) != 0.0); + case CHR: + return tnil(num != chr(0)); + case RNG: + return tnil(nzerop(from(num)) || nzerop(to(num))); + default: + not_number(self, num); + } +} + val plusp(val num) { val self = lit("plusp"); diff --git a/eval.c b/eval.c index b26dc5b1..9cfeba03 100644 --- a/eval.c +++ b/eval.c @@ -6445,6 +6445,7 @@ void eval_init(void) reg_fun(intern(lit("numberp"), user_package), func_n1(numberp)); reg_fun(intern(lit("zerop"), user_package), func_n1(zerop)); + reg_fun(intern(lit("nzerop"), user_package), func_n1(nzerop)); reg_fun(intern(lit("plusp"), user_package), func_n1(plusp)); reg_fun(intern(lit("minusp"), user_package), func_n1(minusp)); reg_fun(intern(lit("evenp"), user_package), func_n1(evenp)); diff --git a/lib.h b/lib.h index d74304db..6570d904 100644 --- a/lib.h +++ b/lib.h @@ -685,6 +685,7 @@ val wrap_star(val start, val end, val num); val wrap(val start, val end, val num); val divi(val anum, val bnum); val zerop(val num); +val nzerop(val num); val plusp(val num); val minusp(val num); val evenp(val num); diff --git a/txr.1 b/txr.1 index 19b0580d..4d1249df 100644 --- a/txr.1 +++ b/txr.1 @@ -35770,9 +35770,10 @@ a or .codn float . -.coNP Function @ zerop +.coNP Functions @ zerop and @ nzerop .synb .mets (zerop << number ) +.mets (nzerop << number ) .syne .desc The @@ -35797,6 +35798,28 @@ and .code nil for all other characters. +If +.meta number +is a range, then +.code zerop +returns +.code t +if both of the range endpoints individually satisfy +.codn zerop . + +The +.code nzerop +function is the logical inverse of +.codn zerop : +it returns +.code t +for those arguments for which +.code zerop +returns +.code nil +and +.IR "vice versa" . + .coNP Functions @ plusp and @ minusp .synb .mets (plusp << number ) -- cgit v1.2.3