bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

copysignl on HP-UX 11


From: Bruno Haible
Subject: copysignl on HP-UX 11
Date: Sun, 6 Nov 2011 19:22:00 +0100
User-agent: KMail/1.13.6 (Linux/2.6.37.6-0.5-desktop; KDE/4.6.0; x86_64; ; )

On HP-UX 11.00..11.31, with cc but not with gcc, the copysignl test fails:

  test-copysignl.c:96: assertion failed
  FAIL: test-copysignl

The reason is that the compiler implements the unary minus operator
incorrectly (!). Here is a workaround, limited to copysignl(), since we
cannot fix the problem in full generality.


2011-11-06  Bruno Haible  <address@hidden>

        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.

--- lib/copysignl.c.orig        Sun Nov  6 19:12:31 2011
+++ lib/copysignl.c     Sun Nov  6 19:10:47 2011
@@ -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
-- 
In memoriam Louis Philippe d'Orléans 
<http://en.wikipedia.org/wiki/Louis_Philippe_II,_Duke_of_Orléans>



reply via email to

[Prev in Thread] Current Thread [Next in Thread]