diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2012-03-21 16:47:46 -0700 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2012-03-21 16:47:46 -0700 |
commit | 3f7c28ed9255ce0332b2e9214ee771c8a1a8dd1c (patch) | |
tree | a70f7ae26d8314d94e4dddc72e0947bf4e6003e7 | |
parent | 551a986c12660fa5a4b36fe22262e7d5255c9994 (diff) | |
download | txr-3f7c28ed9255ce0332b2e9214ee771c8a1a8dd1c.tar.gz txr-3f7c28ed9255ce0332b2e9214ee771c8a1a8dd1c.tar.bz2 txr-3f7c28ed9255ce0332b2e9214ee771c8a1a8dd1c.zip |
* arith.c (divi): New function.
* eval.c (eval_init): divi registered as / intrinsic.
* lib.h (divi): Declared.
* txr.1: divi added to stub heading.
* txr.vim: / operator highlighted.
-rw-r--r-- | ChangeLog | 12 | ||||
-rw-r--r-- | arith.c | 38 | ||||
-rw-r--r-- | eval.c | 1 | ||||
-rw-r--r-- | lib.h | 1 | ||||
-rw-r--r-- | txr.1 | 2 | ||||
-rw-r--r-- | txr.vim | 2 |
6 files changed, 54 insertions, 2 deletions
@@ -1,5 +1,17 @@ 2012-03-21 Kaz Kylheku <kaz@kylheku.com> + * arith.c (divi): New function. + + * eval.c (eval_init): divi registered as / intrinsic. + + * lib.h (divi): Declared. + + * txr.1: divi added to stub heading. + + * txr.vim: / operator highlighted. + +2012-03-21 Kaz Kylheku <kaz@kylheku.com> + * arith.c (mod): Floating support. 2012-03-21 Kaz Kylheku <kaz@kylheku.com> @@ -880,6 +880,44 @@ divzero: uw_throw(numeric_error_s, lit("mod: division by zero")); } +val divi(val anum, val bnum) +{ + switch (type(anum)) { + case NUM: + case BGNUM: + anum = flo_int(anum); + case FLNUM: + break; + default: + goto type; + } + + switch (type(bnum)) { + case NUM: + case BGNUM: + bnum = flo_int(bnum); + case FLNUM: + break; + default: + goto type; + } + + { + double a = c_flo(anum); + double b = c_flo(bnum); + + if (b == 0.0) + goto divzero; + + return flo(a / b); + } + +divzero: + uw_throw(numeric_error_s, lit("divi: division by zero")); +type: + uw_throwf(error_s, lit("divi: invalid operands ~s ~s"), anum, bnum, nao); +} + val zerop(val num) { if (num == zero) @@ -2182,6 +2182,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("expt"), user_package), func_n0v(exptv)); reg_fun(intern(lit("exptmod"), user_package), func_n3(exptmod)); reg_fun(intern(lit("sqrt"), user_package), func_n1(isqrt)); @@ -405,6 +405,7 @@ val mul(val anum, val bnum); val mulv(val nlist); val trunc(val anum, val bnum); val mod(val anum, val bnum); +val divi(val anum, val bnum); val zerop(val num); val evenp(val num); val oddp(val num); @@ -6641,7 +6641,7 @@ symbols, packages, or streams are equal if they are the same hash. Certain object types have a custom equal function. -.SS Arithmetic functions +, -, *, trunc, mod, expt, sqrt +.SS Arithmetic functions +, -, *, /, trunc, mod, expt, sqrt .SS Arithmetic function exptmod @@ -42,7 +42,7 @@ syn keyword txl_keyword contained second third fourth fifth sixth copy-list nrev syn keyword txl_keyword contained reverse ldiff flatten lazy-flatten syn keyword txl_keyword contained memq memql memqual tree-find some syn keyword txl_keyword contained remq remql remqual -syn keyword txl_keyword contained all none eq eql equal + - * abs trunc mod +syn keyword txl_keyword contained all none eq eql equal + - * / abs trunc mod syn keyword txl_keyword contained expt exptmod sqrt gcd fixnump bignump syn keyword txl_keyword contained integerp floatp syn keyword txl_keyword contained numberp zerop evenp oddp > |