* [PATCH] math: fix expf(-NAN) to return -NAN instead of 0
@ 2016-03-04 21:37 Szabolcs Nagy
2016-03-04 21:40 ` Szabolcs Nagy
2016-03-04 22:06 ` Szabolcs Nagy
0 siblings, 2 replies; 4+ messages in thread
From: Szabolcs Nagy @ 2016-03-04 21:37 UTC (permalink / raw)
To: musl; +Cc: Petr Hosek
expf(-NAN) was treated as expf(-large) which unconditionally
returns +0, so special case +-NAN.
reported by Petr Hosek.
---
src/math/expf.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/src/math/expf.c b/src/math/expf.c
index 16e9afe..4a742e4 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;
--
2.7.0
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] math: fix expf(-NAN) to return -NAN instead of 0
2016-03-04 21:37 [PATCH] math: fix expf(-NAN) to return -NAN instead of 0 Szabolcs Nagy
@ 2016-03-04 21:40 ` Szabolcs Nagy
2016-03-04 22:06 ` Szabolcs Nagy
1 sibling, 0 replies; 4+ messages in thread
From: Szabolcs Nagy @ 2016-03-04 21:40 UTC (permalink / raw)
To: musl, Petr Hosek
* Szabolcs Nagy <nsz@port70.net> [2016-03-04 22:37:53 +0100]:
> expf(-NAN) was treated as expf(-large) which unconditionally
> returns +0, so special case +-NAN.
>
> reported by Petr Hosek.
> ---
> src/math/expf.c | 2 ++
> 1 file changed, 2 insertions(+)
>
> diff --git a/src/math/expf.c b/src/math/expf.c
> index 16e9afe..4a742e4 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 */
in the comment -87... should be 87...
but i didnt want to include that into the bug fix
> + if (hx > 0x7f800000) /* +-NaN */
> + return x;
> if (hx >= 0x42b17218 && !sign) { /* x >= 88.722839f */
> /* overflow */
> x *= 0x1p127f;
> --
> 2.7.0
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] math: fix expf(-NAN) to return -NAN instead of 0
2016-03-04 21:37 [PATCH] math: fix expf(-NAN) to return -NAN instead of 0 Szabolcs Nagy
2016-03-04 21:40 ` Szabolcs Nagy
@ 2016-03-04 22:06 ` Szabolcs Nagy
2016-03-06 0:59 ` Rich Felker
1 sibling, 1 reply; 4+ messages in thread
From: Szabolcs Nagy @ 2016-03-04 22:06 UTC (permalink / raw)
To: musl, Petr Hosek
[-- Attachment #1: Type: text/plain, Size: 147 bytes --]
attached a better version with exp2f fix too.
as far as i can tell other functions handle -nan correctly,
but i will have to do some -nan testing.
[-- Attachment #2: 0001-math-fix-expf-NAN-and-exp2f-NAN-to-return-NAN-instea.patch --]
[-- Type: text/x-diff, Size: 1252 bytes --]
From d805064900932fdd47f119f0932680a93184cca6 Mon Sep 17 00:00:00 2001
From: Szabolcs Nagy <nsz@port70.net>
Date: Fri, 4 Mar 2016 21:23:33 +0000
Subject: [PATCH] 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.
---
src/math/exp2f.c | 2 ++
src/math/expf.c | 2 ++
2 files changed, 4 insertions(+)
diff --git a/src/math/exp2f.c b/src/math/exp2f.c
index cf6126e..296b634 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 16e9afe..feee2b0 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;
--
2.7.0
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2016-03-06 0:59 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-03-04 21:37 [PATCH] math: fix expf(-NAN) to return -NAN instead of 0 Szabolcs Nagy
2016-03-04 21:40 ` Szabolcs Nagy
2016-03-04 22:06 ` Szabolcs Nagy
2016-03-06 0:59 ` Rich Felker
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/musl/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).