Commit 83086838 authored by Bruno Haible's avatar Bruno Haible

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.
parent 98ba3c74
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.
......@@ -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:
......
......@@ -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@
......
Files:
tests/test-math.c
tests/macros.h
Depends-on:
math-c++-tests
......
......@@ -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;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment