diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2017-02-25 22:00:50 -0800 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2017-02-25 22:00:50 -0800 |
commit | 0f32fe85728e4ee35a25094d99bdf7b3ff1630a7 (patch) | |
tree | 568160ac3679e3cc202b28bf2fd262786187871f /arith.c | |
parent | 56f0df1ea9282f1c050e23c78fed47f321ff8d06 (diff) | |
download | txr-0f32fe85728e4ee35a25094d99bdf7b3ff1630a7.tar.gz txr-0f32fe85728e4ee35a25094d99bdf7b3ff1630a7.tar.bz2 txr-0f32fe85728e4ee35a25094d99bdf7b3ff1630a7.zip |
Second argument optional in trunc.
* arith.c (trunc1): New static function.
(trunc): Detect a missing second argument and call func1.
* eval.c (eval_init): Update registration of trunc
intrinsic to make second arg optional.
* txr.1: Describe optional argument of trunc. Trunc documentation
is merged with the floor, ceil and round section.
The mod and trunc-rem functions are split off into their own
sections, leaving the / function described by itself.
The documentation of / is substantially revised.
Diffstat (limited to 'arith.c')
-rw-r--r-- | arith.c | 21 |
1 files changed, 21 insertions, 0 deletions
@@ -803,8 +803,29 @@ tail: uw_throwf(error_s, lit("*: invalid operands ~s ~s"), anum, bnum, nao); } +static val trunc1(val num) +{ + switch (type(num)) { + case NUM: + case BGNUM: + return num; + case FLNUM: + { + double n = c_flo(num); + return flo(n - fmod(n, 1.0)); + } + case RNG: + return rcons(trunc1(from(num)), trunc1(to(num))); + default: + break; + } + uw_throwf(error_s, lit("trunc: invalid operand ~s"), num); +} + val trunc(val anum, val bnum) { + if (missingp(bnum)) + return trunc1(anum); tail: switch (TAG_PAIR(tag(anum), tag(bnum))) { case TAG_PAIR(TAG_NUM, TAG_NUM): |