diff options
-rw-r--r-- | eval.c | 2 | ||||
-rw-r--r-- | lib.c | 17 | ||||
-rw-r--r-- | lib.h | 1 | ||||
-rw-r--r-- | txr.1 | 8 |
4 files changed, 25 insertions, 3 deletions
@@ -4776,7 +4776,7 @@ void eval_init(void) reg_fun(intern(lit("trunc-rem"), user_package), func_n2(trunc_rem)); reg_fun(intern(lit("wrap"), user_package), func_n3(wrap)); reg_fun(intern(lit("wrap*"), user_package), func_n3(wrap_star)); - reg_fun(intern(lit("/"), user_package), func_n2o(divi, 1)); + reg_fun(intern(lit("/"), user_package), func_n1v(divv)); reg_fun(intern(lit("expt"), user_package), func_n0v(exptv)); reg_fun(intern(lit("exptmod"), user_package), func_n3(exptmod)); reg_fun(intern(lit("isqrt"), user_package), func_n1(isqrt)); @@ -2650,6 +2650,23 @@ val mulv(struct args *nlist) return nary_op(mul, nlist, one); } +val divv(val dividend, struct args *nlist) +{ + cnum index = 0; + val fi; + + if (!args_more(nlist, 0)) + return divi(one, dividend); + + fi = args_get(nlist, &index); + + if (!args_more(nlist, 0)) + return divi(dividend, fi); + + return reduce_left(func_n2(divi), args_get_list(nlist), + divi(dividend, fi), nil); +} + val logandv(struct args *nlist) { return nary_op(logand, nlist, negone); @@ -602,6 +602,7 @@ val neg(val num); val abso(val num); val mul(val anum, val bnum); val mulv(struct args *); +val divv(val dividend, struct args *); val trunc(val anum, val bnum); val mod(val anum, val bnum); val trunc_rem(val anum, val bnum); @@ -26837,7 +26837,7 @@ A character may not be an operand of multiplication. .coNP Functions @, / @ trunc, @ mod and @ trunc-rem .synb -.mets (/ <> [ dividend ] << divisor ) +.mets (/ <> [ dividend ] << divisor *) .mets (trunc < dividend << divisor ) .mets (mod < dividend << divisor ) .mets (trunc-rem < dividend << divisor ) @@ -26853,7 +26853,11 @@ converted to floating-point type, if necessary. If is omitted, then it is taken to be .code 1.0 -and the function calculates the reciprocal. +and the function calculates the reciprocal. Of these division functions, +only this one may be called with just one argument, or with more than two +arguments. If there are more than two arguments, then each additional argument +is treated as an additional divisor which further divides the result of the +division by the previous divisors. The .code trunc |