From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/9464 Path: news.gmane.org!not-for-mail From: Szabolcs Nagy Newsgroups: gmane.linux.lib.musl.general Subject: Re: [PATCH] math: fix expf(-NAN) to return -NAN instead of 0 Date: Fri, 4 Mar 2016 23:06:32 +0100 Message-ID: <20160304220632.GO29662@port70.net> References: <20160304213753.GM29662@port70.net> Reply-To: musl@lists.openwall.com NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="0eh6TmSyL6TZE2Uz" X-Trace: ger.gmane.org 1457129210 1279 80.91.229.3 (4 Mar 2016 22:06:50 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Fri, 4 Mar 2016 22:06:50 +0000 (UTC) To: musl@lists.openwall.com, Petr Hosek Original-X-From: musl-return-9477-gllmg-musl=m.gmane.org@lists.openwall.com Fri Mar 04 23:06:48 2016 Return-path: Envelope-to: gllmg-musl@m.gmane.org Original-Received: from mother.openwall.net ([195.42.179.200]) by plane.gmane.org with smtp (Exim 4.69) (envelope-from ) id 1abxrz-00039D-1m for gllmg-musl@m.gmane.org; Fri, 04 Mar 2016 23:06:47 +0100 Original-Received: (qmail 29771 invoked by uid 550); 4 Mar 2016 22:06:44 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Original-Received: (qmail 29753 invoked from network); 4 Mar 2016 22:06:43 -0000 Mail-Followup-To: musl@lists.openwall.com, Petr Hosek Content-Disposition: inline In-Reply-To: <20160304213753.GM29662@port70.net> User-Agent: Mutt/1.5.24 (2015-08-30) Xref: news.gmane.org gmane.linux.lib.musl.general:9464 Archived-At: --0eh6TmSyL6TZE2Uz Content-Type: text/plain; charset=us-ascii Content-Disposition: inline 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. --0eh6TmSyL6TZE2Uz Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="0001-math-fix-expf-NAN-and-exp2f-NAN-to-return-NAN-instea.patch" >From d805064900932fdd47f119f0932680a93184cca6 Mon Sep 17 00:00:00 2001 From: Szabolcs Nagy 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 --0eh6TmSyL6TZE2Uz--