math: Ensure HUGE_VAL, HUGE_VALF, HUGE_VALL are defined.
authorBruno Haible <bruno@clisp.org>
Tue, 28 Feb 2012 19:40:59 +0000 (20:40 +0100)
committerBruno Haible <bruno@clisp.org>
Wed, 29 Feb 2012 11:10:53 +0000 (12:10 +0100)
* lib/math.in.h (HUGE_VAL, HUGE_VALF, HUGE_VALL): Define fallbacks.
* tests/test-math.c: Include macros.h. Check that HUGE_VAL, HUGE_VALF,
HUGE_VALL are defined.
(numeric_equald): Renamed from numeric_equal.
(numeric_equalf, numeric_equall): New functions.
(main): Check also HUGE_VALF, HUGE_VALL.
* modules/math-tests (Files): Add tests/macros.h.
* doc/posix-headers/math.texi: Document the problems with HUGE_VALF and
HUGE_VALL.

ChangeLog
doc/posix-headers/math.texi
lib/math.in.h
modules/math-tests
tests/test-math.c

index b3a8d5d..306a47b 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,18 @@
 2012-02-28  Bruno Haible  <bruno@clisp.org>
 
+       math: Ensure HUGE_VAL, HUGE_VALF, HUGE_VALL are defined.
+       * lib/math.in.h (HUGE_VAL, HUGE_VALF, HUGE_VALL): Define fallbacks.
+       * tests/test-math.c: Include macros.h. Check that HUGE_VAL, HUGE_VALF,
+       HUGE_VALL are defined.
+       (numeric_equald): Renamed from numeric_equal.
+       (numeric_equalf, numeric_equall): New functions.
+       (main): Check also HUGE_VALF, HUGE_VALL.
+       * modules/math-tests (Files): Add tests/macros.h.
+       * doc/posix-headers/math.texi: Document the problems with HUGE_VALF and
+       HUGE_VALL.
+
+2012-02-28  Bruno Haible  <bruno@clisp.org>
+
        doc: Move ISO C11 feature notes into POSIX chapters.
        * doc/posix-functions/aligned_alloc.texi: Renamed from
        doc/glibc-functions/aligned_alloc.texi.
index d181f76..d4578d1 100644 (file)
@@ -25,6 +25,11 @@ glibc.
 The macros @code{NAN} and @code{HUGE_VAL} expand to a function address
 rather than a floating point constant on some platforms:
 Solaris 10.
+
+@item
+The macros @code{HUGE_VALF} and @code{HUGE_VALL} are not defined on some
+platforms:
+glibc/HPPA, glibc/SPARC, AIX 5.1, IRIX 6.5, Solaris 9, MSVC 9.
 @end itemize
 
 Portability problems not fixed by Gnulib:
index ce52710..a2d1489 100644 (file)
@@ -141,10 +141,43 @@ _NaN ()
 /* Solaris 10 defines HUGE_VAL, but as a function pointer rather
    than a floating point constant.  */
 #if @REPLACE_HUGE_VAL@
+# undef HUGE_VALF
+# define HUGE_VALF (1.0f / 0.0f)
 # undef HUGE_VAL
 # define HUGE_VAL (1.0 / 0.0)
+# undef HUGE_VALL
+# define HUGE_VALL (1.0L / 0.0L)
 #endif
 
+/* HUGE_VALF is a 'float' Infinity.  */
+#ifndef HUGE_VALF
+# if defined _MSC_VER
+/* The Microsoft MSVC 9 compiler chokes on the expression 1.0f / 0.0f.  */
+#  define HUGE_VALF (1e25f * 1e25f)
+# else
+#  define HUGE_VALF (1.0f / 0.0f)
+# endif
+#endif
+
+/* HUGE_VAL is a 'double' Infinity.  */
+#ifndef HUGE_VAL
+# if defined _MSC_VER
+/* The Microsoft MSVC 9 compiler chokes on the expression 1.0 / 0.0.  */
+#  define HUGE_VAL (1e250 * 1e250)
+# else
+#  define HUGE_VAL (1.0 / 0.0)
+# endif
+#endif
+
+/* HUGE_VALL is a 'long double' Infinity.  */
+#ifndef HUGE_VALL
+# if defined _MSC_VER
+/* The Microsoft MSVC 9 compiler chokes on the expression 1.0L / 0.0L.  */
+#  define HUGE_VALL (1e250L * 1e250L)
+# else
+#  define HUGE_VALL (1.0L / 0.0L)
+# endif
+#endif
 
 #if @GNULIB_ACOSF@
 # if !@HAVE_ACOSF@
index 84c9141..6699945 100644 (file)
@@ -1,5 +1,6 @@
 Files:
 tests/test-math.c
+tests/macros.h
 
 Depends-on:
 math-c++-tests
index f6e61a7..25be63a 100644 (file)
 choke me
 #endif
 
+#ifndef HUGE_VALF
+# error HUGE_VALF should be defined
+choke me
+#endif
+
+#ifndef HUGE_VAL
+# error HUGE_VAL should be defined
+choke me
+#endif
+
+#ifndef HUGE_VALL
+# error HUGE_VALL should be defined
+choke me
+#endif
+
+#include "macros.h"
+
 #if 0
 /* Check that NAN expands into a constant expression.  */
 static float n = NAN;
@@ -34,7 +51,17 @@ static float n = NAN;
    This is a separate function because IRIX 6.5 "cc -O" miscompiles an
    'x == x' test.  */
 static int
-numeric_equal (double x, double y)
+numeric_equalf (float x, float y)
+{
+  return x == y;
+}
+static int
+numeric_equald (double x, double y)
+{
+  return x == y;
+}
+static int
+numeric_equall (long double x, long double y)
 {
   return x == y;
 }
@@ -44,10 +71,16 @@ main (void)
 {
   double d = NAN;
   double zero = 0.0;
-  if (numeric_equal (d, d))
-    return 1;
+  ASSERT (!numeric_equald (d, d));
+
   d = HUGE_VAL;
-  if (!numeric_equal (d, 1.0 / zero))
-    return 1;
+  ASSERT (numeric_equald (d, 1.0 / zero));
+
+  ASSERT (numeric_equalf (HUGE_VALF, HUGE_VALF + HUGE_VALF));
+
+  ASSERT (numeric_equald (HUGE_VAL, HUGE_VAL + HUGE_VAL));
+
+  ASSERT (numeric_equall (HUGE_VALL, HUGE_VALL + HUGE_VALL));
+
   return 0;
 }