diff options
-rw-r--r-- | ChangeLog | 10 | ||||
-rw-r--r-- | arith.c | 17 | ||||
-rw-r--r-- | eval.c | 2 | ||||
-rw-r--r-- | txr.1 | 5 |
4 files changed, 26 insertions, 8 deletions
@@ -1,5 +1,15 @@ 2014-07-20 Kaz Kylheku <kaz@kylheku.com> + * 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 <kaz@kylheku.com> + * genvim.txr: Fixed highlighting issues in numbers followed by newline. * txr.vim: Regenerated. @@ -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) @@ -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)); @@ -10807,7 +10807,7 @@ A character may not be an operand of multiplication. .TP Syntax: - (/ <dividend> <divisor>) + (/ [<dividend>] <divisor>) (trunc <dividend> <divisor>) (mod <dividend> <divisor>) @@ -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 <dividend> is omitted, +then it is taken to be 1.0 and the function performs a reciprocal. The trunc function performs a division of <dividend> by <divisor> whose result is truncated to integer toward zero. If both operands are integers, then an |