summaryrefslogtreecommitdiffstats
path: root/arith.c
diff options
context:
space:
mode:
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);
}
}