]> Savannah Git Hosting - gnulib.git/commitdiff
copysignl: Fix result for zero argument on HP-UX 11 with HP C.
authorBruno Haible <bruno@clisp.org>
Sun, 6 Nov 2011 18:17:07 +0000 (19:17 +0100)
committerBruno Haible <bruno@clisp.org>
Sun, 6 Nov 2011 18:17:07 +0000 (19:17 +0100)
* 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.

ChangeLog
lib/copysignl.c

index 2a12bf74eafa2153949638d3ab174dc4eff958aa..7806432312e48425daa454602f8b992cf23177d2 100644 (file)
--- 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.
index 285b8042d59b4f4b6c5bdad6ab132d426daceda8..44325776017a2fc699a05b490bafdc1190e5abfc 100644 (file)
@@ -29,10 +29,44 @@ copysignl (long double x, long double y)
 
 #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