summaryrefslogtreecommitdiffstats
path: root/arith.c
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2022-11-20 21:33:40 -0800
committerKaz Kylheku <kaz@kylheku.com>2022-11-20 21:33:40 -0800
commit3a84aceb203928c5718553bc56cb3648caa3fcb1 (patch)
treea3679fd0570cf37154ed47582204f0ee4fd83b74 /arith.c
parent0242cf2e537bc1faad5c4650e6e06e4eac6b6d23 (diff)
downloadtxr-3a84aceb203928c5718553bc56cb3648caa3fcb1.tar.gz
txr-3a84aceb203928c5718553bc56cb3648caa3fcb1.tar.bz2
txr-3a84aceb203928c5718553bc56cb3648caa3fcb1.zip
expt: zero exponent yields 1.0.
* arith.c (expt): NUM-FLNUM, FLNUM-NUM and FLNUM-FLNUM cases ensure that if the expontent is zero, the return value is 1.0. Implementations of pow do this, but ISO C doesn't require it. * txr.1: Now documented.
Diffstat (limited to 'arith.c')
-rw-r--r--arith.c6
1 files changed, 6 insertions, 0 deletions
diff --git a/arith.c b/arith.c
index fad3e15b..32f3da44 100644
--- a/arith.c
+++ b/arith.c
@@ -2468,6 +2468,8 @@ tail:
cnum a = c_n(anum);
double b = c_flo(bnum, self);
+ if (b == 0.0)
+ return flo(1.0);
if (a == 0 && b < 0)
goto divzero;
return flo(pow(a, b));
@@ -2477,6 +2479,8 @@ tail:
double a = c_flo(anum, self);
cnum b = c_n(bnum);
+ if (b == 0)
+ return flo(1.0);
if (a == 0 && b < 0)
goto divzero;
return flo(pow(a, b));
@@ -2486,6 +2490,8 @@ tail:
{
double a = c_flo(anum, self);
double b = c_flo(bnum, self);
+ if (b == 0.0)
+ return flo(1.0);
if (a == 0 && b < 0)
goto divzero;
return flo(pow(a, b));