# HG changeset patch # User Bruno Haible # Date 1333465486 -7200 # Node ID a56cad559c24160818f7a036e76ce65248c74f72 # Parent d1ceeee15d927b1d61c88dab0f2dcdc477aec42d math: Provide FP_ILOGB0 and FP_ILOGBNAN. * lib/math.in.h (FP_ILOGB0, FP_ILOGBNAN): Define fallback. * tests/test-math.c: Check that FP_ILOGB0, FP_ILOGBNAN are defined. (main): Check their values. * doc/posix-headers/math.texi: Mention the FP_ILOGB0, FP_ILOGBNAN problem. diff --git a/ChangeLog b/ChangeLog --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2012-04-03 Bruno Haible + + math: Provide FP_ILOGB0 and FP_ILOGBNAN. + * lib/math.in.h (FP_ILOGB0, FP_ILOGBNAN): Define fallback. + * tests/test-math.c: Check that FP_ILOGB0, FP_ILOGBNAN are defined. + (main): Check their values. + * doc/posix-headers/math.texi: Mention the FP_ILOGB0, FP_ILOGBNAN + problem. + 2012-04-03 Bruno Haible Tests for module 'logbl-ieee'. diff --git a/doc/posix-headers/math.texi b/doc/posix-headers/math.texi --- a/doc/posix-headers/math.texi +++ b/doc/posix-headers/math.texi @@ -30,6 +30,11 @@ 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. + +@item +The macros @code{FP_ILOGB0} and @code{FP_ILOGBNAN} are not defined on some +platforms: +NetBSD 5.1, AIX 5.1, IRIX 6.5, Solaris 9, MSVC 9. @end itemize Portability problems not fixed by Gnulib: diff --git a/lib/math.in.h b/lib/math.in.h --- a/lib/math.in.h +++ b/lib/math.in.h @@ -179,6 +179,29 @@ # endif #endif + +/* Ensure FP_ILOGB0 and FP_ILOGBNAN are defined. */ +#if !(defined FP_ILOGB0 && defined FP_ILOGBNAN) +# if defined __NetBSD__ || defined __sgi + /* NetBSD, IRIX 6.5: match what ilogb() does */ +# define FP_ILOGB0 (- 2147483647 - 1) /* INT_MIN */ +# define FP_ILOGBNAN (- 2147483647 - 1) /* INT_MIN */ +# elif defined _AIX + /* AIX 5.1: match what ilogb() does in AIX >= 5.2 */ +# define FP_ILOGB0 (- 2147483647 - 1) /* INT_MIN */ +# define FP_ILOGBNAN 2147483647 /* INT_MAX */ +# elif defined __sun + /* Solaris 9: match what ilogb() does */ +# define FP_ILOGB0 (- 2147483647) /* - INT_MAX */ +# define FP_ILOGBNAN 2147483647 /* INT_MAX */ +# else + /* Gnulib defined values. */ +# define FP_ILOGB0 (- 2147483647) /* - INT_MAX */ +# define FP_ILOGBNAN (- 2147483647 - 1) /* INT_MIN */ +# endif +#endif + + #if @GNULIB_ACOSF@ # if !@HAVE_ACOSF@ # undef acosf diff --git a/tests/test-math.c b/tests/test-math.c --- a/tests/test-math.c +++ b/tests/test-math.c @@ -40,6 +40,18 @@ choke me #endif +#ifndef FP_ILOGB0 +# error FP_ILOGB0 should be defined +choke me +#endif + +#ifndef FP_ILOGBNAN +# error FP_ILOGBNAN should be defined +choke me +#endif + +#include + #include "macros.h" #if 0 @@ -82,5 +94,11 @@ ASSERT (numeric_equall (HUGE_VALL, HUGE_VALL + HUGE_VALL)); + /* Check the value of FP_ILOGB0. */ + ASSERT (FP_ILOGB0 == INT_MIN || FP_ILOGB0 == - INT_MAX); + + /* Check the value of FP_ILOGBNAN. */ + ASSERT (FP_ILOGBNAN == INT_MIN || FP_ILOGBNAN == INT_MAX); + return 0; }