summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSzabolcs Nagy <nsz@port70.net>2016-03-04 21:23:33 +0000
committerRich Felker <dalias@aerifal.cx>2016-03-04 17:58:49 -0500
commitb023c03b574acdfd73418314a5dcaa83e5cea5a0 (patch)
tree87a59e15a8cb6f344deb87a0f3cc88d31fefefea /src
parentdb66ef1f7db7c5b672591a97a97bc789c9efe2f3 (diff)
downloadmusl-b023c03b574acdfd73418314a5dcaa83e5cea5a0.tar.gz
math: fix expf(-NAN) and exp2f(-NAN) to return -NAN instead of 0
expf(-NAN) was treated as expf(-large) which unconditionally returns +0, so special case +-NAN. reported by Petr Hosek.
Diffstat (limited to 'src')
-rw-r--r--src/math/exp2f.c2
-rw-r--r--src/math/expf.c2
2 files changed, 4 insertions, 0 deletions
diff --git a/src/math/exp2f.c b/src/math/exp2f.c
index cf6126ee..296b6343 100644
--- a/src/math/exp2f.c
+++ b/src/math/exp2f.c
@@ -91,6 +91,8 @@ float exp2f(float x)
/* Filter out exceptional cases. */
ix = u.i & 0x7fffffff;
if (ix > 0x42fc0000) { /* |x| > 126 */
+ if (ix > 0x7f800000) /* NaN */
+ return x;
if (u.i >= 0x43000000 && u.i < 0x80000000) { /* x >= 128 */
x *= 0x1p127f;
return x;
diff --git a/src/math/expf.c b/src/math/expf.c
index 16e9afe6..feee2b0e 100644
--- a/src/math/expf.c
+++ b/src/math/expf.c
@@ -39,6 +39,8 @@ float expf(float x)
/* special cases */
if (hx >= 0x42aeac50) { /* if |x| >= -87.33655f or NaN */
+ if (hx > 0x7f800000) /* NaN */
+ return x;
if (hx >= 0x42b17218 && !sign) { /* x >= 88.722839f */
/* overflow */
x *= 0x1p127f;