math: fix expf(-NAN) and exp2f(-NAN) to return -NAN instead of 0
authorSzabolcs Nagy <nsz@port70.net>
Fri, 4 Mar 2016 21:23:33 +0000 (21:23 +0000)
committerRich Felker <dalias@aerifal.cx>
Fri, 4 Mar 2016 22:58:49 +0000 (17:58 -0500)
expf(-NAN) was treated as expf(-large) which unconditionally
returns +0, so special case +-NAN.
reported by Petr Hosek.

src/math/exp2f.c
src/math/expf.c

index cf6126eea776afb939aca1ff32ba3149e1f2ebb5..296b63436f6443a5edfe5915d844f332bc899583 100644 (file)
@@ -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;
index 16e9afe62a21cbd09d6845f8076fb37e4fa5a560..feee2b0ed21741c88f520d354655bccaaca7f402 100644 (file)
@@ -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;