summaryrefslogtreecommitdiffstats
path: root/arith.c
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2012-03-21 07:59:24 -0700
committerKaz Kylheku <kaz@kylheku.com>2012-03-21 07:59:24 -0700
commite7d17c45b37c145eff23a8fc6e602346f9b65fe3 (patch)
tree4707fff0bfd23dea474923bf31edac2e56511626 /arith.c
parente399295ee017de3fe490c4c952701c95baa019e9 (diff)
downloadtxr-e7d17c45b37c145eff23a8fc6e602346f9b65fe3.tar.gz
txr-e7d17c45b37c145eff23a8fc6e602346f9b65fe3.tar.bz2
txr-e7d17c45b37c145eff23a8fc6e602346f9b65fe3.zip
* arith.c (neg): Floating-point support.
* parser.l: FLO and FLODOT cases had to be reordered because the lex trailing context counts as part of the match length, causing 3.0 to be matched as three characters with 0 as the trailing context. The cases are split up to eliminate a flex warning. * stream.c (vformat): Support bignum in floating point conversion. Bugfixes: floating point conversion was accessing obj->fl.n instead of using n. Changed some if/else ladders to switches.
Diffstat (limited to 'arith.c')
-rw-r--r--arith.c20
1 files changed, 13 insertions, 7 deletions
diff --git a/arith.c b/arith.c
index f2f033ea..838d39dd 100644
--- a/arith.c
+++ b/arith.c
@@ -490,13 +490,19 @@ tail:
val neg(val anum)
{
- if (bignump(anum)) {
- val n = make_bignum();
- mp_neg(mp(anum), mp(n));
- return n;
- } else {
- cnum n = c_num(anum);
- return num(-n);
+ switch (type(anum)) {
+ case BGNUM:
+ {
+ val n = make_bignum();
+ mp_neg(mp(anum), mp(n));
+ return n;
+ }
+ case FLNUM:
+ return flo(-c_flo(anum));
+ case NUM:
+ return num(-c_num(anum));
+ default:
+ uw_throwf(error_s, lit("neg: ~s is not a number"), anum, nao);
}
}