bug-gnulib
[Top][All Lists]
Advanced

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

math: support for HUGE_VALF and HUGE_VALL


From: Bruno Haible
Subject: math: support for HUGE_VALF and HUGE_VALL
Date: Tue, 28 Feb 2012 20:45:18 +0100
User-agent: KMail/4.7.4 (Linux/3.1.0-1.2-desktop; KDE/4.7.4; x86_64; ; )

On some platforms, HUGE_VALF and HUGE_VALL are not defined. This fixes it.


2012-02-28  Bruno Haible  <address@hidden>

        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.

index d181f76..d4578d1 100644
--- a/doc/posix-headers/math.texi
+++ b/doc/posix-headers/math.texi
@@ -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.
+
address@hidden
+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
--- a/lib/math.in.h
+++ b/lib/math.in.h
@@ -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 address@hidden@
index 84c9141..6699945 100644
--- a/modules/math-tests
+++ b/modules/math-tests
@@ -1,5 +1,6 @@
 Files:
 tests/test-math.c
+tests/macros.h
 
 Depends-on:
 math-c++-tests
index f6e61a7..25be63a 100644
--- a/tests/test-math.c
+++ b/tests/test-math.c
@@ -25,6 +25,23 @@
 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;
 }




reply via email to

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