summaryrefslogtreecommitdiffstats
path: root/lib/libm/src/e_powf.c
diff options
context:
space:
mode:
authorkettenis <kettenis@openbsd.org>2013-08-02 20:23:28 +0000
committerkettenis <kettenis@openbsd.org>2013-08-02 20:23:28 +0000
commitd205ab02eabefec09df68de8ff35e0519ffc9a86 (patch)
treebd1af2e134d4ae75481b006c069142022a9a87d2 /lib/libm/src/e_powf.c
parentNo longer needed since miod taught elf to mkuboot. (diff)
downloadwireguard-openbsd-d205ab02eabefec09df68de8ff35e0519ffc9a86.tar.xz
wireguard-openbsd-d205ab02eabefec09df68de8ff35e0519ffc9a86.zip
Fix a couple of corner cases in the implementation of pow(3) to make it
compatible with C99. Most notably: - 1**y == 1, even if y is NaN - (-1)**+-Inf == 1 and adjust the cephes testsuite to test for the right thing here. ok martynas@
Diffstat (limited to 'lib/libm/src/e_powf.c')
-rw-r--r--lib/libm/src/e_powf.c5
1 files changed, 4 insertions, 1 deletions
diff --git a/lib/libm/src/e_powf.c b/lib/libm/src/e_powf.c
index d6e52d8b99b..3c4269d7146 100644
--- a/lib/libm/src/e_powf.c
+++ b/lib/libm/src/e_powf.c
@@ -64,6 +64,9 @@ powf(float x, float y)
/* y==zero: x**0 = 1 */
if(iy==0) return one;
+ /* x==1: 1**y = 1, even if y is NaN */
+ if (hx==0x3f800000) return one;
+
/* +-NaN return x+y */
if(ix > 0x7f800000 ||
iy > 0x7f800000)
@@ -87,7 +90,7 @@ powf(float x, float y)
/* special value of y */
if (iy==0x7f800000) { /* y is +-inf */
if (ix==0x3f800000)
- return y - y; /* inf**+-1 is NaN */
+ return one; /* (-1)**+-inf is NaN */
else if (ix > 0x3f800000)/* (|x|>1)**+-inf = inf,0 */
return (hy>=0)? y: zero;
else /* (|x|<1)**-,+inf = inf,0 */