public inbox for cygwin-cvs@sourceware.org
help / color / mirror / Atom feed
* [newlib-cygwin] Cygwin: math: Properly propagate input NANs in a few functions
@ 2019-08-20 16:16 Corinna Vinschen
  0 siblings, 0 replies; only message in thread
From: Corinna Vinschen @ 2019-08-20 16:16 UTC (permalink / raw)
  To: cygwin-cvs

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain; charset="us-ascii", Size: 3581 bytes --]

https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=f7f296b46f2607814c326ea1ed9b3294eb746034

commit f7f296b46f2607814c326ea1ed9b3294eb746034
Author: Martin Storsjö <martin@martin.st>
Date:   Thu Jul 25 00:13:13 2019 +0300

    Cygwin: math: Properly propagate input NANs in a few functions
    
    While the C99 standard doesn't explicitly require this, the standard
    says it is recommended (F.9.13).
    
    Signed-off-by: Martin Storsjö <martin@martin.st>

Diff:
---
 winsup/cygwin/math/acosh.def.h |  7 ++++++-
 winsup/cygwin/math/erfl.c      |  3 +++
 winsup/cygwin/math/lgammal.c   |  2 +-
 winsup/cygwin/math/log.def.h   |  4 ++--
 winsup/cygwin/math/pow.def.h   | 10 +++++++---
 winsup/cygwin/math/tgammal.c   |  2 +-
 6 files changed, 20 insertions(+), 8 deletions(-)

diff --git a/winsup/cygwin/math/acosh.def.h b/winsup/cygwin/math/acosh.def.h
index 1fc5deb..870be36 100644
--- a/winsup/cygwin/math/acosh.def.h
+++ b/winsup/cygwin/math/acosh.def.h
@@ -50,7 +50,12 @@ __FLT_TYPE
 __FLT_ABI(acosh) (__FLT_TYPE x)
 {
   int x_class = fpclassify (x);
-  if (x_class == FP_NAN || x < __FLT_CST(1.0))
+  if (x_class == FP_NAN)
+    {
+      errno = EDOM;
+      return x;
+    }
+  else if (x < __FLT_CST(1.0))
     {
       errno = EDOM;
       return __FLT_NAN;
diff --git a/winsup/cygwin/math/erfl.c b/winsup/cygwin/math/erfl.c
index 3832fe9..bfd8d33 100644
--- a/winsup/cygwin/math/erfl.c
+++ b/winsup/cygwin/math/erfl.c
@@ -243,6 +243,9 @@ long double erfcl(long double a)
 	if (isinf (a))
 		return (signbit(a) ? 2.0 : 0.0);
 
+	if (isnan (a))
+		return (a);
+
 	x = fabsl (a);
 
 	if (x < 1.0L)
diff --git a/winsup/cygwin/math/lgammal.c b/winsup/cygwin/math/lgammal.c
index 03c030e..533ef75 100644
--- a/winsup/cygwin/math/lgammal.c
+++ b/winsup/cygwin/math/lgammal.c
@@ -216,7 +216,7 @@ long double __lgammal_r(long double x, int* sgngaml)
 	*sgngaml = 1;
 #ifdef NANS
 	if (isnanl(x))
-		return(NANL);
+		return x;
 #endif
 #ifdef INFINITIES
 	if (!isfinitel(x))
diff --git a/winsup/cygwin/math/log.def.h b/winsup/cygwin/math/log.def.h
index 2ba7421..b4121e9 100644
--- a/winsup/cygwin/math/log.def.h
+++ b/winsup/cygwin/math/log.def.h
@@ -56,6 +56,8 @@ __FLT_ABI(log) (__FLT_TYPE x)
       errno = ERANGE;
       return -__FLT_HUGE_VAL;
     }
+  else if (x_class == FP_NAN)
+    return x;
   else if (signbit (x))
     {
       errno = EDOM;
@@ -63,7 +65,5 @@ __FLT_ABI(log) (__FLT_TYPE x)
     }
   else if (x_class == FP_INFINITE)
     return __FLT_HUGE_VAL;
-  else if (x_class == FP_NAN)
-    return __FLT_NAN;
   return (__FLT_TYPE) __logl_internal ((long double) x);
 }
diff --git a/winsup/cygwin/math/pow.def.h b/winsup/cygwin/math/pow.def.h
index e1538d9..b004c09 100644
--- a/winsup/cygwin/math/pow.def.h
+++ b/winsup/cygwin/math/pow.def.h
@@ -121,9 +121,13 @@ __FLT_ABI(pow) (__FLT_TYPE x, __FLT_TYPE y)
     return __FLT_CST(1.0);
   else if (x_class == FP_NAN || y_class == FP_NAN)
     {
-      rslt = (signbit(x) ? -__FLT_NAN : __FLT_NAN);
-      errno = EDOM;
-      return rslt;
+      if (x_class == FP_NAN) {
+        errno = EDOM;
+        return x;
+      } else {
+        errno = EDOM;
+        return y;
+      }
     }
   else if (x_class == FP_ZERO)
     {
diff --git a/winsup/cygwin/math/tgammal.c b/winsup/cygwin/math/tgammal.c
index 25a37ea..910706d 100644
--- a/winsup/cygwin/math/tgammal.c
+++ b/winsup/cygwin/math/tgammal.c
@@ -272,7 +272,7 @@ long double __tgammal_r(long double x, int* sgngaml)
 	*sgngaml = 1;
 #ifdef NANS
 	if (isnanl(x))
-		return (NANL);
+		return x;
 #endif
 #ifdef INFINITIES
 #ifdef NANS


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2019-08-20 16:16 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-08-20 16:16 [newlib-cygwin] Cygwin: math: Properly propagate input NANs in a few functions 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).