changeset 16048:e2ff993ff145

copysignl: Fix result for zero argument on HP-UX 11 with HP C. * lib/copysignl.c (compute_minus_zerol) [HP-UX]: New function. (minus_zerol) [HP-UX]: New macro. (unary_minus) [HP-UX]: New function. (copysignl) [HP-UX]: Use unary_minus function.
author Bruno Haible <bruno@clisp.org>
date Sun, 06 Nov 2011 19:17:07 +0100
parents 843e85c12830
children 910a456a8fda
files ChangeLog lib/copysignl.c
diffstat 2 files changed, 42 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2011-11-06  Bruno Haible  <bruno@clisp.org>
+
+	copysignl: Fix result for zero argument on HP-UX 11 with HP C.
+	* lib/copysignl.c (compute_minus_zerol) [HP-UX]: New function.
+	(minus_zerol) [HP-UX]: New macro.
+	(unary_minus) [HP-UX]: New function.
+	(copysignl) [HP-UX]: Use unary_minus function.
+
 2011-11-06  Bruno Haible  <bruno@clisp.org>
 
 	ldexp, ldexpf, ldexpl: Enhance tests.
--- a/lib/copysignl.c
+++ b/lib/copysignl.c
@@ -29,10 +29,44 @@
 
 #else
 
+# if defined __hpux && !defined __GNUC__
+
+#  include <float.h>
+
+/* HP cc on HP-UX 10.20 has a bug with the constant expression -0.0L.  */
+static long double
+compute_minus_zerol (void)
+{
+  return -LDBL_MIN * LDBL_MIN;
+}
+#  define minus_zerol compute_minus_zerol ()
+
+/* HP cc on HP-UX 11 has a bug: When x is a positive zero, - x comes out
+   as a positive zero, rather than as a minus zero.  Work around it.  */
+static long double
+unary_minus (long double x)
+{
+  if (x == 0.0L)
+    {
+      if (signbit (x))
+        return 0.0L;
+      else
+        return minus_zerol;
+    }
+  else
+    return - x;
+}
+
+# endif
+
 long double
 copysignl (long double x, long double y)
 {
+# if defined __hpux && !defined __GNUC__
+  return (signbit (x) != signbit (y) ? unary_minus (x) : x);
+# else
   return (signbit (x) != signbit (y) ? - x : x);
+# endif
 }
 
 #endif