Welcome to mirror list, hosted at ThFree Co, Russian Federation.

cygwin.com/git/newlib-cygwin.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKeith Packard via Newlib <newlib@sourceware.org>2020-03-26 03:18:19 +0300
committerCorinna Vinschen <corinna@vinschen.de>2020-03-26 14:21:33 +0300
commit61cd34c1bfab626c084fd4289657b8f1ac43a138 (patch)
tree6f4d1f39322c196203a8d6136a6032a1e9de2126 /newlib/libm/common
parent5e24839658f6576b68b26c977897b9ad3fc3c23f (diff)
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>
Diffstat (limited to 'newlib/libm/common')
-rw-r--r--newlib/libm/common/s_modf.c10
-rw-r--r--newlib/libm/common/sf_modf.c10
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
@@ -64,12 +64,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
double modf(x, iptr)
@@ -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
@@ -16,12 +16,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
float modff(x, iptr)
@@ -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;