public inbox for newlib@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] Fix modf/f for NaN input
@ 2020-03-18 13:18 Fabian Schriever
  2020-03-19 15:43 ` Corinna Vinschen
  0 siblings, 1 reply; 2+ messages in thread
From: Fabian Schriever @ 2020-03-18 13:18 UTC (permalink / raw)
  To: newlib; +Cc: Fabian Schriever

For NaN input the modf/f procedures should return NaN instead of zero
with the sign of the input.
---
 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;
-- 
2.24.1.windows.2



^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] Fix modf/f for NaN input
  2020-03-18 13:18 [PATCH] Fix modf/f for NaN input Fabian Schriever
@ 2020-03-19 15:43 ` Corinna Vinschen
  0 siblings, 0 replies; 2+ messages in thread
From: Corinna Vinschen @ 2020-03-19 15:43 UTC (permalink / raw)
  To: Fabian Schriever; +Cc: newlib

[-- Attachment #1: Type: text/plain, Size: 1423 bytes --]

On Mar 18 14:18, Fabian Schriever wrote:
> For NaN input the modf/f procedures should return NaN instead of zero
> with the sign of the input.
> ---
>  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;
> -- 
> 2.24.1.windows.2
> 

Pushed.


Thanks,
Corinna

-- 
Corinna Vinschen
Cygwin Maintainer
Red Hat

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2020-03-19 15:43 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-03-18 13:18 [PATCH] Fix modf/f for NaN input Fabian Schriever
2020-03-19 15:43 ` Corinna Vinschen

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).