Mercurial > hg > octave-lojdl > gnulib-hg
changeset 16510:af909bf507e4
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.
author | Bruno Haible <bruno@clisp.org> |
---|---|
date | Tue, 28 Feb 2012 20:40:59 +0100 |
parents | d2a4b2dea076 |
children | 2074f2bf7216 |
files | ChangeLog doc/posix-headers/math.texi lib/math.in.h modules/math-tests tests/test-math.c |
diffstat | 5 files changed, 90 insertions(+), 5 deletions(-) [+] |
line wrap: on
line diff
--- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,16 @@ +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.
--- a/doc/posix-headers/math.texi +++ b/doc/posix-headers/math.texi @@ -25,6 +25,11 @@ 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:
--- a/lib/math.in.h +++ b/lib/math.in.h @@ -141,10 +141,43 @@ /* 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@
--- 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
--- 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 @@ 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 @@ { 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; }