aboutsummaryrefslogtreecommitdiff
path: root/newlib/libm
diff options
context:
space:
mode:
authorFabian Schriever <fabian.schriever@gtd-gmbh.de>2020-03-18 14:18:20 +0100
committerCorinna Vinschen <corinna@vinschen.de>2020-03-19 16:34:26 +0100
commit4ad9ba42fc3dd116bad8b9cb89d434256d3431fb (patch)
tree56f0cf51cfdcda5e013a88f1dcb0529cebb1bd29 /newlib/libm
parent9e8da7bd2138aaefcb746be3bcce2787c75a5849 (diff)
downloadnewlib-4ad9ba42fc3dd116bad8b9cb89d434256d3431fb.zip
newlib-4ad9ba42fc3dd116bad8b9cb89d434256d3431fb.tar.gz
newlib-4ad9ba42fc3dd116bad8b9cb89d434256d3431fb.tar.bz2
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.
Diffstat (limited to 'newlib/libm')
-rw-r--r--newlib/libm/common/s_modf.c1
-rw-r--r--newlib/libm/common/sf_modf.c1
2 files changed, 2 insertions, 0 deletions
diff --git a/newlib/libm/common/s_modf.c b/newlib/libm/common/s_modf.c
index 8551a99..c948b85 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 6c64e3f..ae97076 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;