isfinite: Avoid compiler bug of "cc -O" on HP-UX 11.11.
authorBruno Haible <bruno@clisp.org>
Sat, 1 Jan 2011 02:54:48 +0000 (03:54 +0100)
committerBruno Haible <bruno@clisp.org>
Sat, 1 Jan 2011 02:54:48 +0000 (03:54 +0100)
* lib/isfinite.c (zerof, zerod, zerol): New variables.
(gl_isfinitef, gl_isfinited, gl_isfinitel): Use them instead of literal
zero.

ChangeLog
lib/isfinite.c

index f3dcc8f..2a0f94f 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,12 @@
 2010-12-31  Bruno Haible  <bruno@clisp.org>
 
+       isfinite: Avoid compiler bug of "cc -O" on HP-UX 11.11.
+       * lib/isfinite.c (zerof, zerod, zerol): New variables.
+       (gl_isfinitef, gl_isfinited, gl_isfinitel): Use them instead of literal
+       zero.
+
+2010-12-31  Bruno Haible  <bruno@clisp.org>
+
        pwrite: Work around HP-UX 11.11 bug.
        * m4/pwrite.m4 (gl_FUNC_PWRITE): When pwrite exists, test whether it
        works and set REPLACE_PWRITE if not.
index fd0d003..8c13cbf 100644 (file)
 #include "isnand-nolibm.h"
 #include "isnanl-nolibm.h"
 
+/* The "cc" compiler on HP-UX 11.11, when optimizing, simplifies the test
+   x - y == 0.0  to  x == y, a simplification which is invalid when x and y
+   are Infinity.  Disable this optimization.  */
+#if defined __hpux && !defined __GNUC__
+static float zerof;
+static double zerod;
+static long double zerol;
+#else
+# define zerof 0.f
+# define zerod 0.
+# define zerol 0.L
+#endif
+
 int gl_isfinitef (float x)
 {
-  return !isnanf (x) && x - x == 0.f;
+  return !isnanf (x) && x - x == zerof;
 }
 
 int gl_isfinited (double x)
 {
-  return !isnand (x) && x - x == 0.;
+  return !isnand (x) && x - x == zerod;
 }
 
 int gl_isfinitel (long double x)
 {
-  return !isnanl (x) && x - x == 0.L;
+  return !isnanl (x) && x - x == zerol;
 }