Re: [PATCH] Fix error in fdim/f for infinities

Corinna Vinschen <[email protected]>
Newsgroups gmane.comp.lib.newlib
Message-ID <[email protected]>
On Mar 10 11:24, Fabian Schriever wrote:
> The comparison c == FP_INFINITE causes the function to return +inf as it
> expects x = +inf to always be larger than y. This shortcut causes
> several issues as it also returns +inf for the following cases:
>  - fdim(+inf, +inf), expected (as per C99): +0.0
>  - fdim(-inf, any non NaN), expected: +0.0
> 
> I don't see a reason to keep the comparison as all the infinity cases
> return the correct result using just the ternary operation.
> ---
>  newlib/libm/common/s_fdim.c  | 5 +----
>  newlib/libm/common/sf_fdim.c | 5 +----
>  2 files changed, 2 insertions(+), 8 deletions(-)
> 
> diff --git a/newlib/libm/common/s_fdim.c b/newlib/libm/common/s_fdim.c
> index 73a027953..61a4908f3 100644
> --- a/newlib/libm/common/s_fdim.c
> +++ b/newlib/libm/common/s_fdim.c
> @@ -49,11 +49,8 @@ ANSI C, POSIX.
>  	double y;
>  #endif
>  {
> -  int c = __fpclassifyd(x);
> -  if (c == FP_NAN)  return(x);
> +  if (__fpclassifyd(x) == FP_NAN)  return(x);
>    if (__fpclassifyd(y) == FP_NAN)  return(y);
> -  if (c == FP_INFINITE)
> -    return HUGE_VAL;
>  
>    return x > y ? x - y : 0.0;
>  }
> diff --git a/newlib/libm/common/sf_fdim.c b/newlib/libm/common/sf_fdim.c
> index fe349098b..8fee57002 100644
> --- a/newlib/libm/common/sf_fdim.c
> +++ b/newlib/libm/common/sf_fdim.c
> @@ -14,11 +14,8 @@
>  	float y;
>  #endif
>  {
> -  int c = __fpclassifyf(x);
> -  if (c == FP_NAN)  return(x);
> +  if (__fpclassifyf(x) == FP_NAN)  return(x);
>    if (__fpclassifyf(y) == FP_NAN)  return(y);
> -  if (c == FP_INFINITE)
> -    return HUGE_VALF;
>  
>    return x > y ? x - y : 0.0;
>  }
> -- 
> 2.24.1.windows.2
> 

Pushed.

Thanks,
Corinna

-- 
Corinna Vinschen
Cygwin Maintainer
Red Hat
signature.asc (application/pgp-signature, 833 B)
-----BEGIN PGP SIGNATURE-----

iQIzBAEBCAAdFiEEoVYPmneWZnwT6kwF9TYGna5ET6AFAl5nqHIACgkQ9TYGna5E
T6Ch0A/8DnZZQUBwAo5tLVOYDZVAvzNJuwLX50nVOUnuEkrmnrKK5HOuExYPkVJ1
bQ0tYL7j+JVTA4a9H8/BVOaXT/7i+X/vwRuOLe3dW7TWHVook+YyLbO2sqmWNyi3
GhV8pDs499YMXlXFMhwN/oEILoMWSia5oXwM5pwschtD8LN6WMy8KNe1A4pmAyO0
eCXjVAJOZuWxdIp257SXenk9+N43poNliXTDXXPuWihWPjJDRfE0aja6YmcC73S6
5OGgZuln0oB7uuHNYg31CYMsgc6CDmW30jpGJThmBLuYbvG2MyIhYeRaGoN+78/F
3+eqFUKP5SJXBkHUw81KBhr2OoicEr3d593twP4RBHtkHnrYYZsdj0n5CLFM9Kwz
roa/+nYiEkhqOYzFoTTJQQNsnpIsxaBWGWdctb2F+dhBio5eiGnYVIkNmPkwdFcM
gFSQBsE5Quf91J4PYNYlNvOkgo7u5DNhVjre0Dz/JJo9LKsdBlxrg9dXm4H+Zekw
ysgl+LwCULvkVGNQzgvQ5/4De6FiQFdfAAMbUKTJlDxAp1UI8jnC8KzJ+g9j5bwp
So9wPwVjVhsl9nRvLkc4xVmqK+vBnGP6poiN77mVowAfWjh/yspqDSVWbAI5baim
ywnhvypJa6hWUUUJlmnPUX0HbpWhPSoqx2OsRkL/KGPfa7C9UHw=
=CeXd
-----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.