From 7da23010b2afbaae4dc4b8f01d1f8950e2c878be Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Sun, 20 Jul 2014 09:07:20 -0700 Subject: * arith.c (divi): Support one-argument form. Use "/" name in error reporting, not "divi". * eval.c (eval_init): Change registration of / so only one argument is required out of two. * txr.1: Document one-argument division. --- ChangeLog | 10 ++++++++++ arith.c | 17 ++++++++++++----- eval.c | 2 +- txr.1 | 5 +++-- 4 files changed, 26 insertions(+), 8 deletions(-) diff --git a/ChangeLog b/ChangeLog index ff4b0b7d..ae8e9302 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2014-07-20 Kaz Kylheku + + * arith.c (divi): Support one-argument form. + Use "/" name in error reporting, not "divi". + + * eval.c (eval_init): Change registration of / so only + one argument is required out of two. + + * txr.1: Document one-argument division. + 2014-07-20 Kaz Kylheku * genvim.txr: Fixed highlighting issues in numbers followed by newline. diff --git a/arith.c b/arith.c index 14d3d0e2..7051ddb8 100644 --- a/arith.c +++ b/arith.c @@ -946,13 +946,20 @@ static val to_float(val func, val num) val divi(val anum, val bnum) { - double a = c_flo(to_float(lit("divi"), anum)); - double b = c_flo(to_float(lit("divi"), bnum)); + if (missingp(bnum)) { + double b = c_flo(to_float(lit("/"), anum)); + if (b == 0.0) + uw_throw(numeric_error_s, lit("/: division by zero")); + return flo(1.0 / b); + } else { + double a = c_flo(to_float(lit("/"), anum)); + double b = c_flo(to_float(lit("/"), bnum)); - if (b == 0.0) - uw_throw(numeric_error_s, lit("divi: division by zero")); + if (b == 0.0) + uw_throw(numeric_error_s, lit("/: division by zero")); - return flo(a / b); + return flo(a / b); + } } val zerop(val num) diff --git a/eval.c b/eval.c index 6e596272..0cd9b73d 100644 --- a/eval.c +++ b/eval.c @@ -3594,7 +3594,7 @@ void eval_init(void) reg_fun(intern(lit("abs"), user_package), func_n1(abso)); reg_fun(intern(lit("trunc"), user_package), func_n2(trunc)); reg_fun(intern(lit("mod"), user_package), func_n2(mod)); - reg_fun(intern(lit("/"), user_package), func_n2(divi)); + reg_fun(intern(lit("/"), user_package), func_n2o(divi, 1)); 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)); diff --git a/txr.1 b/txr.1 index b3f4b3b8..5ffacc85 100644 --- a/txr.1 +++ b/txr.1 @@ -10807,7 +10807,7 @@ A character may not be an operand of multiplication. .TP Syntax: - (/ ) + (/ [] ) (trunc ) (mod ) @@ -10816,7 +10816,8 @@ Description: The arguments to these functions are numbers. Characters are not permitted. The / function performs floating-point division. Each operands is first -converted to floating-point type, if necessary. +converted to floating-point type, if necessary. If is omitted, +then it is taken to be 1.0 and the function performs a reciprocal. The trunc function performs a division of by whose result is truncated to integer toward zero. If both operands are integers, then an -- cgit v1.2.3