bug-gnulib
[Top][All Lists]
Advanced

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

[PATCH] strtod: work around icc bug


From: Eric Blake
Subject: [PATCH] strtod: work around icc bug
Date: Fri, 5 Nov 2010 08:37:42 -0600

With optimization, ICC 10.0 mis-compiles 'cond ? -val : val' such
that a val of 0.0 doesn't result in -0.0.

* lib/strtod.c (minus_zero): Define to working value.
(strtod): Use it to avoid icc bug.

Signed-off-by: Eric Blake <address@hidden>
---

This fixes strtod under icc with optimization, which had been silently
broken until yesterday's testsuite patches exposed the compiler bug.

 ChangeLog    |    4 ++++
 lib/strtod.c |   19 +++++++++++++++++++
 2 files changed, 23 insertions(+), 0 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 7af53b8..1711e5b 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,9 @@
 2010-11-05  Eric Blake  <address@hidden>

+       strtod: work around icc bug
+       * lib/strtod.c (minus_zero): Define to working value.
+       (strtod): Use it to avoid icc bug.
+
        copysign: enhance tests
        * modules/copysign-tests (Files): Add minus-zero.h.
        * tests/test-copysign.c (main): Also test zeros.
diff --git a/lib/strtod.c b/lib/strtod.c
index 060dffa..cd61add 100644
--- a/lib/strtod.c
+++ b/lib/strtod.c
@@ -190,6 +190,21 @@ parse_number (const char *nptr,

 static double underlying_strtod (const char *, char **);

+/* HP cc on HP-UX 10.20 has a bug with the constant expression -0.0.
+   ICC 10.0 has a bug when optimizing the expression -zero.
+   The expression -DBL_MIN * DBL_MIN does not work when cross-compiling
+   to PowerPC on MacOS X 10.5.  */
+#if defined __hpux || defined __sgi || defined __ICC
+static double
+compute_minus_zero (void)
+{
+  return -DBL_MIN * DBL_MIN;
+}
+# define minus_zero compute_minus_zero ()
+#else
+double minus_zero = -0.0;
+#endif
+
 /* Convert NPTR to a double.  If ENDPTR is not NULL, a pointer to the
    character after the last one used in the number is put in *ENDPTR.  */
 double
@@ -320,6 +335,10 @@ strtod (const char *nptr, char **endptr)

   if (endptr != NULL)
     *endptr = (char *) s;
+  /* Special case -0.0, since at least ICC miscompiles negation.  We
+     can't use copysign(), as that drags in -lm on some platforms.  */
+  if (!num && negative)
+    return minus_zero;
   return negative ? -num : num;
 }

-- 
1.7.3.2




reply via email to

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