[PATCH] Cygwin: fix return value of sqrtl on negative infinity

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

[PATCH] Cygwin: fix return value of sqrtl on negative infinity

cygwin-patches mailing list
The return value is now -NaN.

This fixes a bug in the mingw-w64 code that was imported into Cygwin.
The fix is consistent with Posix and Linux.  It is also consistent
with the current mingw-w64 code, with one exception: The mingw-w64
code sets errno to EDOM if the input is -NaN, but this appears to
differ from Posix and Linux.

Addresses: https://cygwin.com/pipermail/cygwin/2020-October/246606.html
---
 winsup/cygwin/math/sqrt.def.h | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/winsup/cygwin/math/sqrt.def.h b/winsup/cygwin/math/sqrt.def.h
index cf8b5cbe6..3d1a00908 100644
--- a/winsup/cygwin/math/sqrt.def.h
+++ b/winsup/cygwin/math/sqrt.def.h
@@ -73,8 +73,11 @@ __FLT_ABI (sqrt) (__FLT_TYPE x)
       if (x_class == FP_ZERO)
  return __FLT_CST (-0.0);
 
+      if (x_class == FP_NAN)
+ return x;
+
       errno = EDOM;
-      return x;
+      return -__FLT_NAN;
     }
   else if (x_class == FP_ZERO)
     return __FLT_CST (0.0);
--
2.28.0

Reply | Threaded
Open this post in threaded view
|

Re: [PATCH] Cygwin: fix return value of sqrtl on negative infinity

Corinna Vinschen-2
On Oct 27 10:10, Ken Brown via Cygwin-patches wrote:

> The return value is now -NaN.
>
> This fixes a bug in the mingw-w64 code that was imported into Cygwin.
> The fix is consistent with Posix and Linux.  It is also consistent
> with the current mingw-w64 code, with one exception: The mingw-w64
> code sets errno to EDOM if the input is -NaN, but this appears to
> differ from Posix and Linux.
>
> Addresses: https://cygwin.com/pipermail/cygwin/2020-October/246606.html
> ---
>  winsup/cygwin/math/sqrt.def.h | 5 ++++-
>  1 file changed, 4 insertions(+), 1 deletion(-)
>
> diff --git a/winsup/cygwin/math/sqrt.def.h b/winsup/cygwin/math/sqrt.def.h
> index cf8b5cbe6..3d1a00908 100644
> --- a/winsup/cygwin/math/sqrt.def.h
> +++ b/winsup/cygwin/math/sqrt.def.h
> @@ -73,8 +73,11 @@ __FLT_ABI (sqrt) (__FLT_TYPE x)
>        if (x_class == FP_ZERO)
>   return __FLT_CST (-0.0);
>  
> +      if (x_class == FP_NAN)
> + return x;
> +
>        errno = EDOM;
> -      return x;
> +      return -__FLT_NAN;
>      }
>    else if (x_class == FP_ZERO)
>      return __FLT_CST (0.0);
> --
> 2.28.0

LGTM


Thanks,
Corinna