From: Szabolcs Nagy <nsz@port70.net>
To: musl@lists.openwall.com, Petr Hosek <phosek@chromium.org>
Subject: Re: [PATCH] math: fix expf(-NAN) to return -NAN instead of 0
Date: Fri, 4 Mar 2016 23:06:32 +0100 [thread overview]
Message-ID: <20160304220632.GO29662@port70.net> (raw)
In-Reply-To: <20160304213753.GM29662@port70.net>
[-- 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
next prev parent reply other threads:[~2016-03-04 22:06 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-03-04 21:37 Szabolcs Nagy
2016-03-04 21:40 ` Szabolcs Nagy
2016-03-04 22:06 ` Szabolcs Nagy [this message]
2016-03-06 0:59 ` Rich Felker
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20160304220632.GO29662@port70.net \
--to=nsz@port70.net \
--cc=musl@lists.openwall.com \
--cc=phosek@chromium.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).