New module 'ilogbl'.
authorBruno Haible <bruno@clisp.org>
Tue, 3 Apr 2012 19:58:52 +0000 (21:58 +0200)
committerBruno Haible <bruno@clisp.org>
Tue, 3 Apr 2012 19:58:52 +0000 (21:58 +0200)
* lib/math.in.h (ilogbl): New declaration.
* lib/ilogbl.c: New file.
* m4/ilogbl.m4: New file.
* m4/math_h.m4 (gl_MATH_H): Test whether ilogbl is declared.
(gl_MATH_H_DEFAULTS): Initialize GNULIB_ILOGBL, HAVE_ILOGBL.
* modules/math (Makefile.am): Substitute GNULIB_ILOGBL, HAVE_ILOGBL.
Split sed invocation, to avoid the limit of 100 substitutions of
HP-UX 'sed'.
* modules/ilogbl: New file.
* tests/test-math-c++.cc: Check the declaration of ilogbl.
* doc/posix-functions/ilogbl.texi: Mention the new module.

ChangeLog
doc/posix-functions/ilogbl.texi
lib/ilogbl.c [new file with mode: 0644]
lib/math.in.h
m4/ilogbl.m4 [new file with mode: 0644]
m4/math_h.m4
modules/ilogbl [new file with mode: 0644]
modules/math
tests/test-math-c++.cc

index 4d5ebc9..9807df9 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,20 @@
 2012-04-03  Bruno Haible  <bruno@clisp.org>
 
+       New module 'ilogbl'.
+       * lib/math.in.h (ilogbl): New declaration.
+       * lib/ilogbl.c: New file.
+       * m4/ilogbl.m4: New file.
+       * m4/math_h.m4 (gl_MATH_H): Test whether ilogbl is declared.
+       (gl_MATH_H_DEFAULTS): Initialize GNULIB_ILOGBL, HAVE_ILOGBL.
+       * modules/math (Makefile.am): Substitute GNULIB_ILOGBL, HAVE_ILOGBL.
+       Split sed invocation, to avoid the limit of 100 substitutions of
+       HP-UX 'sed'.
+       * modules/ilogbl: New file.
+       * tests/test-math-c++.cc: Check the declaration of ilogbl.
+       * doc/posix-functions/ilogbl.texi: Mention the new module.
+
+2012-04-03  Bruno Haible  <bruno@clisp.org>
+
        Tests for module 'ilogbf'.
        * modules/ilogbf-tests: New file.
        * tests/test-ilogbf.c: New file.
index 4205ac3..9580a5c 100644 (file)
@@ -4,15 +4,15 @@
 
 POSIX specification:@* @url{http://www.opengroup.org/onlinepubs/9699919799/functions/ilogbl.html}
 
-Gnulib module: ---
+Gnulib module: ilogbl
 
 Portability problems fixed by Gnulib:
 @itemize
+@item
+This function is missing on some platforms:
+FreeBSD 5.2.1, NetBSD 5.0, OpenBSD 3.8, Minix 3.1.8, AIX 5.1, HP-UX 11, IRIX 6.5, Solaris 9, Cygwin, MSVC 9, Interix 3.5, BeOS.
 @end itemize
 
 Portability problems not fixed by Gnulib:
 @itemize
-@item
-This function is missing on some platforms:
-FreeBSD 5.2.1, NetBSD 5.0, OpenBSD 3.8, Minix 3.1.8, AIX 5.1, HP-UX 11, IRIX 6.5, Solaris 9, Cygwin, MSVC 9, Interix 3.5, BeOS.
 @end itemize
diff --git a/lib/ilogbl.c b/lib/ilogbl.c
new file mode 100644 (file)
index 0000000..4613d94
--- /dev/null
@@ -0,0 +1,35 @@
+/* Floating-point exponent.
+   Copyright (C) 2012 Free Software Foundation, Inc.
+
+   This program is free software: you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+#include <config.h>
+
+/* Specification.  */
+#include <math.h>
+
+#if HAVE_SAME_LONG_DOUBLE_AS_DOUBLE
+
+int
+ilogbl (long double x)
+{
+  return ilogb (x);
+}
+
+#else
+
+# define USE_LONG_DOUBLE
+# include "ilogb.c"
+
+#endif
index 74fca3a..0625777 100644 (file)
@@ -1133,6 +1133,20 @@ _GL_WARN_ON_USE (ilogb, "ilogb is unportable - "
 # endif
 #endif
 
+#if @GNULIB_ILOGBL@
+# if !@HAVE_ILOGBL@
+_GL_FUNCDECL_SYS (ilogbl, int, (long double x));
+# endif
+_GL_CXXALIAS_SYS (ilogbl, int, (long double x));
+_GL_CXXALIASWARN (ilogbl);
+#elif defined GNULIB_POSIXCHECK
+# undef ilogbl
+# if HAVE_RAW_DECL_ILOGBL
+_GL_WARN_ON_USE (ilogbl, "ilogbl is unportable - "
+                 "use gnulib module ilogbl for portability");
+# endif
+#endif
+
 
 /* Return x * 2^exp.  */
 #if @GNULIB_LDEXPF@
diff --git a/m4/ilogbl.m4 b/m4/ilogbl.m4
new file mode 100644 (file)
index 0000000..e7f871f
--- /dev/null
@@ -0,0 +1,61 @@
+# ilogbl.m4 serial 1
+dnl Copyright (C) 2010-2012 Free Software Foundation, Inc.
+dnl This file is free software; the Free Software Foundation
+dnl gives unlimited permission to copy and/or distribute it,
+dnl with or without modifications, as long as this notice is preserved.
+
+AC_DEFUN([gl_FUNC_ILOGBL],
+[
+  AC_REQUIRE([gl_MATH_H_DEFAULTS])
+  AC_REQUIRE([gl_LONG_DOUBLE_VS_DOUBLE])
+  AC_REQUIRE([gl_FUNC_ILOGB])
+
+  dnl Persuade glibc <math.h> to declare ilogbl().
+  AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
+
+  dnl Test whether ilogbl() exists. Assume that ilogbl(), if it exists, is
+  dnl defined in the same library as ilogb().
+  save_LIBS="$LIBS"
+  LIBS="$LIBS $ILOGB_LIBM"
+  AC_CACHE_CHECK([for ilogbl],
+    [gl_cv_func_ilogbl],
+    [
+      AC_LINK_IFELSE(
+        [AC_LANG_PROGRAM(
+           [[#ifndef __NO_MATH_INLINES
+             # define __NO_MATH_INLINES 1 /* for glibc */
+             #endif
+             #include <math.h>
+             int (*funcptr) (long double) = ilogbl;
+             long double x;]],
+           [[return (funcptr (x) % 2) == 0
+                    || (ilogbl (x) % 2) == 0;]])],
+        [gl_cv_func_ilogbl=yes],
+        [gl_cv_func_ilogbl=no])
+    ])
+  LIBS="$save_LIBS"
+  if test $gl_cv_func_ilogbl = yes; then
+    ILOGBL_LIBM="$ILOGB_LIBM"
+  else
+    HAVE_ILOGBL=0
+    dnl Find libraries needed to link lib/ilogbl.c.
+    if test $HAVE_SAME_LONG_DOUBLE_AS_DOUBLE = 1; then
+      ILOGBL_LIBM="$ILOGB_LIBM"
+    else
+      AC_REQUIRE([gl_FUNC_FREXPL])
+      AC_REQUIRE([gl_FUNC_ISNANL])
+      ILOGBL_LIBM=
+      dnl Append $FREXPL_LIBM to ILOGBL_LIBM, avoiding gratuitous duplicates.
+      case " $ILOGBL_LIBM " in
+        *" $FREXPL_LIBM "*) ;;
+        *) ILOGBL_LIBM="$ILOGBL_LIBM $FREXPL_LIBM" ;;
+      esac
+      dnl Append $ISNANL_LIBM to ILOGBL_LIBM, avoiding gratuitous duplicates.
+      case " $ILOGBL_LIBM " in
+        *" $ISNANL_LIBM "*) ;;
+        *) ILOGBL_LIBM="$ILOGBL_LIBM $ISNANL_LIBM" ;;
+      esac
+    fi
+  fi
+  AC_SUBST([ILOGBL_LIBM])
+])
index c00c415..90d248a 100644 (file)
@@ -1,4 +1,4 @@
-# math_h.m4 serial 112
+# math_h.m4 serial 113
 dnl Copyright (C) 2007-2012 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -44,7 +44,7 @@ AC_DEFUN([gl_MATH_H],
      expf expl exp2 exp2f exp2l expm1 expm1f expm1l
      fabsf fabsl floorf floorl fma fmaf fmal
      fmod fmodf fmodl frexpf frexpl hypotf hypotl
-     ilogb ilogbf
+     ilogb ilogbf ilogbl
      ldexpf ldexpl
      log logf logl log10 log10f log10l log1p log1pf log1pl log2 log2f log2l
      logb logbf logbl
@@ -111,6 +111,7 @@ AC_DEFUN([gl_MATH_H_DEFAULTS],
   GNULIB_HYPOTL=0;     AC_SUBST([GNULIB_HYPOTL])
   GNULIB_ILOGB=0;      AC_SUBST([GNULIB_ILOGB])
   GNULIB_ILOGBF=0;     AC_SUBST([GNULIB_ILOGBF])
+  GNULIB_ILOGBL=0;     AC_SUBST([GNULIB_ILOGBL])
   GNULIB_ISFINITE=0;   AC_SUBST([GNULIB_ISFINITE])
   GNULIB_ISINF=0;      AC_SUBST([GNULIB_ISINF])
   GNULIB_ISNAN=0;      AC_SUBST([GNULIB_ISNAN])
@@ -191,6 +192,7 @@ AC_DEFUN([gl_MATH_H_DEFAULTS],
   HAVE_HYPOTL=1;               AC_SUBST([HAVE_HYPOTL])
   HAVE_ILOGB=1;                AC_SUBST([HAVE_ILOGB])
   HAVE_ILOGBF=1;               AC_SUBST([HAVE_ILOGBF])
+  HAVE_ILOGBL=1;               AC_SUBST([HAVE_ILOGBL])
   HAVE_ISNANF=1;               AC_SUBST([HAVE_ISNANF])
   HAVE_ISNAND=1;               AC_SUBST([HAVE_ISNAND])
   HAVE_ISNANL=1;               AC_SUBST([HAVE_ISNANL])
diff --git a/modules/ilogbl b/modules/ilogbl
new file mode 100644 (file)
index 0000000..103f088
--- /dev/null
@@ -0,0 +1,37 @@
+Description:
+ilogbl() function: get exponent as integer.
+
+Files:
+lib/ilogbl.c
+lib/ilogb.c
+m4/ilogbl.m4
+m4/mathfunc.m4
+
+Depends-on:
+math
+extensions
+ilogb           [test $HAVE_ILOGBL = 0 && test $HAVE_SAME_LONG_DOUBLE_AS_DOUBLE = 1]
+isfinite        [test $HAVE_ILOGBL = 0 && test $HAVE_SAME_LONG_DOUBLE_AS_DOUBLE = 0]
+frexpl          [test $HAVE_ILOGBL = 0 && test $HAVE_SAME_LONG_DOUBLE_AS_DOUBLE = 0]
+isnanl          [test $HAVE_ILOGBL = 0 && test $HAVE_SAME_LONG_DOUBLE_AS_DOUBLE = 0]
+
+configure.ac:
+gl_FUNC_ILOGBL
+if test $HAVE_ILOGBL = 0; then
+  AC_LIBOBJ([ilogbl])
+fi
+gl_MATH_MODULE_INDICATOR([ilogbl])
+
+Makefile.am:
+
+Include:
+<math.h>
+
+Link:
+$(ILOGBL_LIBM)
+
+License:
+LGPL
+
+Maintainer:
+Bruno Haible
index a2ef168..57f223e 100644 (file)
@@ -72,8 +72,10 @@ math.h: math.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(ARG_NONNULL_H) $(
              -e 's/@''GNULIB_HYPOT''@/$(GNULIB_HYPOT)/g' \
              -e 's/@''GNULIB_HYPOTF''@/$(GNULIB_HYPOTF)/g' \
              -e 's/@''GNULIB_HYPOTL''@/$(GNULIB_HYPOTL)/g' \
-             -e 's/@''GNULIB_ILOGB''@/$(GNULIB_ILOGB)/g' \
+             < $(srcdir)/math.in.h | \
+         sed -e 's/@''GNULIB_ILOGB''@/$(GNULIB_ILOGB)/g' \
              -e 's/@''GNULIB_ILOGBF''@/$(GNULIB_ILOGBF)/g' \
+             -e 's/@''GNULIB_ILOGBL''@/$(GNULIB_ILOGBL)/g' \
              -e 's/@''GNULIB_ISFINITE''@/$(GNULIB_ISFINITE)/g' \
              -e 's/@''GNULIB_ISINF''@/$(GNULIB_ISINF)/g' \
              -e 's/@''GNULIB_ISNAN''@/$(GNULIB_ISNAN)/g' \
@@ -122,7 +124,7 @@ math.h: math.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(ARG_NONNULL_H) $(
              -e 's/@''GNULIB_TRUNC''@/$(GNULIB_TRUNC)/g' \
              -e 's/@''GNULIB_TRUNCF''@/$(GNULIB_TRUNCF)/g' \
              -e 's/@''GNULIB_TRUNCL''@/$(GNULIB_TRUNCL)/g' \
-             < $(srcdir)/math.in.h | \
+         | \
          sed -e 's|@''HAVE_ACOSF''@|$(HAVE_ACOSF)|g' \
              -e 's|@''HAVE_ACOSL''@|$(HAVE_ACOSL)|g' \
              -e 's|@''HAVE_ASINF''@|$(HAVE_ASINF)|g' \
@@ -154,6 +156,7 @@ math.h: math.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(ARG_NONNULL_H) $(
              -e 's|@''HAVE_HYPOTL''@|$(HAVE_HYPOTL)|g' \
              -e 's|@''HAVE_ILOGB''@|$(HAVE_ILOGB)|g' \
              -e 's|@''HAVE_ILOGBF''@|$(HAVE_ILOGBF)|g' \
+             -e 's|@''HAVE_ILOGBL''@|$(HAVE_ILOGBL)|g' \
              -e 's|@''HAVE_ISNANF''@|$(HAVE_ISNANF)|g' \
              -e 's|@''HAVE_ISNAND''@|$(HAVE_ISNAND)|g' \
              -e 's|@''HAVE_ISNANL''@|$(HAVE_ISNANL)|g' \
index 45fc2a3..00ed7d0 100644 (file)
@@ -200,6 +200,9 @@ SIGNATURE_CHECK (GNULIB_NAMESPACE::ilogbf, int, (float));
 #if GNULIB_TEST_ILOGB
 SIGNATURE_CHECK (GNULIB_NAMESPACE::ilogb, int, (double));
 #endif
+#if GNULIB_TEST_ILOGBL
+SIGNATURE_CHECK (GNULIB_NAMESPACE::ilogbl, int, (long double));
+#endif
 
 //SIGNATURE_CHECK (GNULIB_NAMESPACE::j0, double, (double));