From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2155) id C6378387102D; Thu, 19 Mar 2020 15:34:51 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C6378387102D Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Corinna Vinschen To: newlib-cvs@sourceware.org Subject: [newlib-cygwin] Fix modf/f for NaN input X-Act-Checkin: newlib-cygwin X-Git-Author: Fabian Schriever X-Git-Refname: refs/heads/master X-Git-Oldrev: 9e8da7bd2138aaefcb746be3bcce2787c75a5849 X-Git-Newrev: 4ad9ba42fc3dd116bad8b9cb89d434256d3431fb Message-Id: <20200319153451.C6378387102D@sourceware.org> Date: Thu, 19 Mar 2020 15:34:51 +0000 (GMT) X-BeenThere: newlib-cvs@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Newlib-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 19 Mar 2020 15:34:51 -0000 https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=4ad9ba42fc3dd116bad8b9cb89d434256d3431fb commit 4ad9ba42fc3dd116bad8b9cb89d434256d3431fb Author: Fabian Schriever Date: Wed Mar 18 14:18:20 2020 +0100 Fix modf/f for NaN input For NaN input the modf/f procedures should return NaN instead of zero with the sign of the input. Diff: --- newlib/libm/common/s_modf.c | 1 + newlib/libm/common/sf_modf.c | 1 + 2 files changed, 2 insertions(+) diff --git a/newlib/libm/common/s_modf.c b/newlib/libm/common/s_modf.c index 8551a99e4..c948b8525 100644 --- a/newlib/libm/common/s_modf.c +++ b/newlib/libm/common/s_modf.c @@ -100,6 +100,7 @@ static double one = 1.0; } else if (j0>51) { /* no fraction part */ __uint32_t high; *iptr = x*one; + if (__fpclassifyd(x) == FP_NAN) return x+x; /* x is NaN, return NaN */ GET_HIGH_WORD(high,x); INSERT_WORDS(x,high&0x80000000,0); /* return +-0 */ return x; diff --git a/newlib/libm/common/sf_modf.c b/newlib/libm/common/sf_modf.c index 6c64e3fa0..ae970762b 100644 --- a/newlib/libm/common/sf_modf.c +++ b/newlib/libm/common/sf_modf.c @@ -52,6 +52,7 @@ static float one = 1.0; } else { /* no fraction part */ __uint32_t ix; *iptr = x*one; + if (__fpclassifyf(x) == FP_NAN) return x+x; /* x is NaN, return NaN */ GET_FLOAT_WORD(ix,x); SET_FLOAT_WORD(x,ix&0x80000000); /* return +-0 */ return x;