changeset 16763:a56cad559c24

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.
author Bruno Haible <bruno@clisp.org>
date Tue, 03 Apr 2012 17:04:46 +0200
parents d1ceeee15d92
children d48f227b07b4
files ChangeLog doc/posix-headers/math.texi lib/math.in.h tests/test-math.c
diffstat 4 files changed, 55 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2012-04-03  Bruno Haible  <bruno@clisp.org>
+
+	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  <bruno@clisp.org>
 
 	Tests for module 'logbl-ieee'.
--- 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:
--- 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
--- 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 <limits.h>
+
 #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;
 }