From: Bruno Haible Date: Tue, 3 Apr 2012 19:58:52 +0000 (+0200) Subject: New module 'ilogbl'. X-Git-Tag: v0.1~758 X-Git-Url: http://erislabs.org.uk/gitweb/?a=commitdiff_plain;h=811b6ef05c574d054648a2f41bc5a2efc92f5371;p=gnulib.git 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. --- diff --git a/ChangeLog b/ChangeLog index 4d5ebc98e..9807df90d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,20 @@ 2012-04-03 Bruno Haible + 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 + Tests for module 'ilogbf'. * modules/ilogbf-tests: New file. * tests/test-ilogbf.c: New file. diff --git a/doc/posix-functions/ilogbl.texi b/doc/posix-functions/ilogbl.texi index 4205ac308..9580a5cfb 100644 --- a/doc/posix-functions/ilogbl.texi +++ b/doc/posix-functions/ilogbl.texi @@ -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 index 000000000..4613d94c9 --- /dev/null +++ b/lib/ilogbl.c @@ -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 . */ + +#include + +/* Specification. */ +#include + +#if HAVE_SAME_LONG_DOUBLE_AS_DOUBLE + +int +ilogbl (long double x) +{ + return ilogb (x); +} + +#else + +# define USE_LONG_DOUBLE +# include "ilogb.c" + +#endif diff --git a/lib/math.in.h b/lib/math.in.h index 74fca3a5e..0625777ac 100644 --- a/lib/math.in.h +++ b/lib/math.in.h @@ -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 index 000000000..e7f871f87 --- /dev/null +++ b/m4/ilogbl.m4 @@ -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 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 + 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]) +]) diff --git a/m4/math_h.m4 b/m4/math_h.m4 index c00c415d4..90d248aec 100644 --- a/m4/math_h.m4 +++ b/m4/math_h.m4 @@ -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 index 000000000..103f0884f --- /dev/null +++ b/modules/ilogbl @@ -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: + + +Link: +$(ILOGBL_LIBM) + +License: +LGPL + +Maintainer: +Bruno Haible diff --git a/modules/math b/modules/math index a2ef168b1..57f223e1d 100644 --- a/modules/math +++ b/modules/math @@ -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' \ diff --git a/tests/test-math-c++.cc b/tests/test-math-c++.cc index 45fc2a380..00ed7d008 100644 --- a/tests/test-math-c++.cc +++ b/tests/test-math-c++.cc @@ -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));