From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from elaine.keithp.com (home.keithp.com [63.227.221.253]) by sourceware.org (Postfix) with ESMTPS id A4A42385E006 for ; Thu, 26 Mar 2020 00:18:25 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org A4A42385E006 Received: from localhost (localhost [127.0.0.1]) by elaine.keithp.com (Postfix) with ESMTP id B10413F2B6CB for ; Wed, 25 Mar 2020 17:18:24 -0700 (PDT) X-Virus-Scanned: Debian amavisd-new at keithp.com Received: from elaine.keithp.com ([127.0.0.1]) by localhost (elaine.keithp.com [127.0.0.1]) (amavisd-new, port 10024) with LMTP id x5fdpBy8SD40; Wed, 25 Mar 2020 17:18:24 -0700 (PDT) Received: from keithp.com (koto.keithp.com [10.0.0.2]) by elaine.keithp.com (Postfix) with ESMTPSA id 65CEF3F2B640; Wed, 25 Mar 2020 17:18:24 -0700 (PDT) Received: by keithp.com (Postfix, from userid 1000) id BB0F11582118; Wed, 25 Mar 2020 17:18:23 -0700 (PDT) From: Keith Packard To: newlib@sourceware.org Subject: [PATCH 1/3] newlib/libm/common: Fix modf/modff returning snan Date: Wed, 25 Mar 2020 17:18:19 -0700 Message-Id: <20200326001821.174426-2-keithp@keithp.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200326001821.174426-1-keithp@keithp.com> References: <20200326001821.174426-1-keithp@keithp.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-27.1 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: newlib@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Newlib mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 26 Mar 2020 00:18:27 -0000 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 --- 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; -- 2.25.1