Re: [PATCH] Fix modf/f for NaN input

Corinna Vinschen via Newlib <[email protected]>
Newsgroups gmane.comp.lib.newlib
Message-ID <[email protected]>
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
signature.asc (application/pgp-signature, 833 B)
-----BEGIN PGP SIGNATURE-----

iQIzBAEBCAAdFiEEoVYPmneWZnwT6kwF9TYGna5ET6AFAl5zkwsACgkQ9TYGna5E
T6CWsRAAoJLWoVF0bANoNhSFY8mPCHESy2QzIgXte+SyGr92uZ67ssGxm0R9l30R
pth5S7e7G1KPitdolvUcU7JOyX7bAHtieR/WHYkxZrIMhdz/o+5RRYBQ60laIKYF
4TCIr69iGS0wDRTpQptE78daO5g0XGk3RDAFHQWF8l1Etbkzj6ruBHTEm172oA7L
HMTc/NawlI/jIVT/9dYvnPMS7NqvKLsW755xQTGtfD0na4X2Z7SatVMvs5caoCVL
O+fBpqLjE0yUyPOlN/uvcGayn2OT53x3DqhYVInD67W4IJHKfqznNvLyRF1ey/ia
9NHwxVijTjAK1fVv36UjAPqW/YM/nU/oYF1jxmTSKnRdXZ21O9J8muklBl3cMZ1L
Mg13eMvrOWwcweMoSfgCX3i/i1aqlUEb1Tsu/KhsSrFuf9Au3NbGn/Y/NZ9ZyMPO
xGe23RBo5OlUT7o/EYhkg/uje2t8hNAo97F9X30nKZcjRZnBdHtygmYahqyUrlIV
eJq4XFRfe0RFfGJO/zTX24FjP6FuZ8zZc0BeGGBjBK7okteE/gbm5NbsTMCr5xn2
pThoostTwYWbZ9vqSt+q10ZeREaUu3Gc+yyiNVMZxRZNmfEcgC6dFdLS5f62Quiw
v0hT+rteQnAhfV4+/jaPww1f9fLwrsSVW28Bf06v9sWD6aP2A7w=
=abqu
-----END PGP SIGNATURE-----
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.