public inbox for newlib-cvs@sourceware.org
help / color / mirror / Atom feed
From: Corinna Vinschen <corinna@sourceware.org>
To: newlib-cvs@sourceware.org
Subject: [newlib-cygwin] newlib/libm/common: Fix modf/modff returning snan
Date: Thu, 26 Mar 2020 11:42:37 +0000 (GMT)	[thread overview]
Message-ID: <20200326114237.70DBA385E00B@sourceware.org> (raw)

https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=61cd34c1bfab626c084fd4289657b8f1ac43a138

commit 61cd34c1bfab626c084fd4289657b8f1ac43a138
Author: Keith Packard via Newlib <newlib@sourceware.org>
Date:   Wed Mar 25 17:18:19 2020 -0700

    newlib/libm/common: Fix modf/modff returning snan
    
    Recent GCC appears to elide multiplication by 1, which causes snan
    parameters to be returned unchanged through *iptr. Use the existing
    conversion of snan to qnan to also set the correct result in *iptr
    instead.
    
    Signed-off-by: Keith Packard <keithp@keithp.com>

Diff:
---
 newlib/libm/common/s_modf.c  | 10 ++--------
 newlib/libm/common/sf_modf.c | 10 ++--------
 2 files changed, 4 insertions(+), 16 deletions(-)

diff --git a/newlib/libm/common/s_modf.c b/newlib/libm/common/s_modf.c
index c948b8525..c826580b4 100644
--- a/newlib/libm/common/s_modf.c
+++ b/newlib/libm/common/s_modf.c
@@ -63,12 +63,6 @@ QUICKREF
 
 #ifndef _DOUBLE_IS_32BITS
 
-#ifdef __STDC__
-static const double one = 1.0;
-#else
-static double one = 1.0;
-#endif
-
 #ifdef __STDC__
 	double modf(double x, double *iptr)
 #else
@@ -99,8 +93,8 @@ 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 */
+	    *iptr = x;
+	    if (__fpclassifyd(x) == FP_NAN) return *iptr = 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 ae970762b..e241e4612 100644
--- a/newlib/libm/common/sf_modf.c
+++ b/newlib/libm/common/sf_modf.c
@@ -15,12 +15,6 @@
 
 #include "fdlibm.h"
 
-#ifdef __STDC__
-static const float one = 1.0;
-#else
-static float one = 1.0;
-#endif
-
 #ifdef __STDC__
 	float modff(float x, float *iptr)
 #else
@@ -51,8 +45,8 @@ 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 */
+	    *iptr = x;
+	    if (__fpclassifyf(x) == FP_NAN) return *iptr = x+x; /* x is NaN, return NaN */
 	    GET_FLOAT_WORD(ix,x);
 	    SET_FLOAT_WORD(x,ix&0x80000000);	/* return +-0 */
 	    return x;


                 reply	other threads:[~2020-03-26 11:42 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20200326114237.70DBA385E00B@sourceware.org \
    --to=corinna@sourceware.org \
    --cc=newlib-cvs@sourceware.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.
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 read-only IMAP folder(s) and NNTP newsgroup(s).