From 6a2bdd8e10abd669186bf2d618bfb1f106c8fcb7 Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Sat, 10 Mar 2012 22:28:49 +0100 Subject: [PATCH] New module 'log1pf'. * lib/math.in.h (log1pf): New declaration. * lib/log1pf.c: New file. * m4/log1pf.m4: New file. * m4/math_h.m4 (gl_MATH_H): Test whether log1pf is declared. (gl_MATH_H_DEFAULTS): Initialize GNULIB_LOG1PF, HAVE_LOG1PF, REPLACE_LOG1PF. * modules/math (Makefile.am): Substitute GNULIB_LOG1PF, HAVE_LOG1PF, REPLACE_LOG1PF. * modules/log1pf: New file. * tests/test-math-c++.cc: Check the declaration of log1pf. * doc/posix-functions/log1pf.texi: Mention the new module. --- ChangeLog | 15 +++++++++ doc/posix-functions/log1pf.texi | 11 ++++--- lib/log1pf.c | 26 +++++++++++++++ lib/math.in.h | 23 +++++++++++++ m4/log1pf.m4 | 72 +++++++++++++++++++++++++++++++++++++++++ m4/math_h.m4 | 8 +++-- modules/log1pf | 32 ++++++++++++++++++ modules/math | 3 ++ tests/test-math-c++.cc | 3 ++ 9 files changed, 187 insertions(+), 6 deletions(-) create mode 100644 lib/log1pf.c create mode 100644 m4/log1pf.m4 create mode 100644 modules/log1pf diff --git a/ChangeLog b/ChangeLog index b8ed3e08b..39e3ddcb9 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,20 @@ 2012-03-10 Bruno Haible + New module 'log1pf'. + * lib/math.in.h (log1pf): New declaration. + * lib/log1pf.c: New file. + * m4/log1pf.m4: New file. + * m4/math_h.m4 (gl_MATH_H): Test whether log1pf is declared. + (gl_MATH_H_DEFAULTS): Initialize GNULIB_LOG1PF, HAVE_LOG1PF, + REPLACE_LOG1PF. + * modules/math (Makefile.am): Substitute GNULIB_LOG1PF, HAVE_LOG1PF, + REPLACE_LOG1PF. + * modules/log1pf: New file. + * tests/test-math-c++.cc: Check the declaration of log1pf. + * doc/posix-functions/log1pf.texi: Mention the new module. + +2012-03-10 Bruno Haible + log1p tests: More tests. * tests/test-log1p.h: New file. * modules/log1p-tests (Files): Add tests/test-log1p.h, tests/randomd.c. diff --git a/doc/posix-functions/log1pf.texi b/doc/posix-functions/log1pf.texi index d5c84865b..2e3c49abe 100644 --- a/doc/posix-functions/log1pf.texi +++ b/doc/posix-functions/log1pf.texi @@ -4,15 +4,18 @@ POSIX specification:@* @url{http://www.opengroup.org/onlinepubs/9699919799/functions/log1pf.html} -Gnulib module: --- +Gnulib module: log1pf Portability problems fixed by Gnulib: @itemize +@item +This function is missing on some platforms: +Minix 3.1.8, AIX 5.1, HP-UX 11, Solaris 9, MSVC 9. +@item +This function returns a wrong value for the argument -1.0f on some platforms: +IRIX 6.5. @end itemize Portability problems not fixed by Gnulib: @itemize -@item -This function is missing on some platforms: -Minix 3.1.8, AIX 5.1, HP-UX 11, Solaris 9, MSVC 9. @end itemize diff --git a/lib/log1pf.c b/lib/log1pf.c new file mode 100644 index 000000000..4d889faa2 --- /dev/null +++ b/lib/log1pf.c @@ -0,0 +1,26 @@ +/* Natural logarithm of 1 plus argument. + 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 + +float +log1pf (float x) +{ + return (float) log1p ((double) x); +} diff --git a/lib/math.in.h b/lib/math.in.h index a479b6d31..9f7147d51 100644 --- a/lib/math.in.h +++ b/lib/math.in.h @@ -1221,6 +1221,29 @@ _GL_WARN_ON_USE (log10l, "log10l is unportable - " #endif +#if @GNULIB_LOG1PF@ +# if @REPLACE_LOG1PF@ +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# undef log1pf +# define log1pf rpl_log1pf +# endif +_GL_FUNCDECL_RPL (log1pf, float, (float x)); +_GL_CXXALIAS_RPL (log1pf, float, (float x)); +# else +# if !@HAVE_LOG1PF@ +_GL_FUNCDECL_SYS (log1pf, float, (float x)); +# endif +_GL_CXXALIAS_SYS (log1pf, float, (float x)); +# endif +_GL_CXXALIASWARN (log1pf); +#elif defined GNULIB_POSIXCHECK +# undef log1pf +# if HAVE_RAW_DECL_LOG1PF +_GL_WARN_ON_USE (log1pf, "log1pf is unportable - " + "use gnulib module log1pf for portability"); +# endif +#endif + #if @GNULIB_LOG1P@ # if !@HAVE_LOG1P@ _GL_FUNCDECL_SYS (log1p, double, (double x)); diff --git a/m4/log1pf.m4 b/m4/log1pf.m4 new file mode 100644 index 000000000..b01243358 --- /dev/null +++ b/m4/log1pf.m4 @@ -0,0 +1,72 @@ +# log1pf.m4 serial 1 +dnl Copyright (C) 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_LOG1PF], +[ + AC_REQUIRE([gl_MATH_H_DEFAULTS]) + AC_REQUIRE([gl_FUNC_LOG1P]) + + dnl Persuade glibc to declare log1pf(). + AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS]) + + dnl Test whether log1pf() exists. Assume that log1pf(), if it exists, is + dnl defined in the same library as log1p(). + save_LIBS="$LIBS" + LIBS="$LIBS $LOG1P_LIBM" + AC_CHECK_FUNCS([log1pf]) + LIBS="$save_LIBS" + if test $ac_cv_func_log1pf = yes; then + LOG1PF_LIBM="$LOG1P_LIBM" + + save_LIBS="$LIBS" + LIBS="$LIBS $LOG1PF_LIBM" + gl_FUNC_LOG1PF_WORKS + LIBS="$save_LIBS" + case "$gl_cv_func_log1pf_works" in + *yes) ;; + *) REPLACE_LOG1PF=1 ;; + esac + else + HAVE_LOG1PF=0 + fi + if test $HAVE_LOG1PF = 0 || test $REPLACE_LOG1PF = 1; then + dnl Find libraries needed to link lib/log1pf.c. + LOG1PF_LIBM="$LOG1P_LIBM" + fi + AC_SUBST([LOG1PF_LIBM]) +]) + +dnl Test whether log1pf() works. +dnl On IRIX 6.5, log1pf(-1.0f) returns +Infinity instead of -Infinity. +AC_DEFUN([gl_FUNC_LOG1PF_WORKS], +[ + AC_REQUIRE([AC_PROG_CC]) + AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles + AC_CACHE_CHECK([whether log1pf works], [gl_cv_func_log1pf_works], + [ + AC_RUN_IFELSE( + [AC_LANG_SOURCE([[ +#include +volatile float x; +float y; +int main () +{ + x = -1.0f; + y = log1pf (x); + if (!(y + y == y && y < 0.0f)) + return 1; + return 0; +} +]])], + [gl_cv_func_log1pf_works=yes], + [gl_cv_func_log1pf_works=no], + [case "$host_os" in + irix*) gl_cv_func_log1pf_works="guessing no";; + *) gl_cv_func_log1pf_works="guessing yes";; + esac + ]) + ]) +]) diff --git a/m4/math_h.m4 b/m4/math_h.m4 index 028d8cd1b..8290c16cc 100644 --- a/m4/math_h.m4 +++ b/m4/math_h.m4 @@ -1,4 +1,4 @@ -# math_h.m4 serial 96 +# math_h.m4 serial 97 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,8 @@ 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 - ldexpf ldexpl logb log logf logl log10f log10l log1p modf modff modfl powf + ldexpf ldexpl logb log logf logl log10f log10l log1p log1pf + modf modff modfl powf remainder remainderf remainderl rint rintf rintl round roundf roundl sinf sinl sinhf sqrtf sqrtl tanf tanl tanhf trunc truncf truncl]) @@ -120,6 +121,7 @@ AC_DEFUN([gl_MATH_H_DEFAULTS], GNULIB_LOG10F=0; AC_SUBST([GNULIB_LOG10F]) GNULIB_LOG10L=0; AC_SUBST([GNULIB_LOG10L]) GNULIB_LOG1P=0; AC_SUBST([GNULIB_LOG1P]) + GNULIB_LOG1PF=0; AC_SUBST([GNULIB_LOG1PF]) GNULIB_MODF=0; AC_SUBST([GNULIB_MODF]) GNULIB_MODFF=0; AC_SUBST([GNULIB_MODFF]) GNULIB_MODFL=0; AC_SUBST([GNULIB_MODFL]) @@ -184,6 +186,7 @@ AC_DEFUN([gl_MATH_H_DEFAULTS], HAVE_LOG10F=1; AC_SUBST([HAVE_LOG10F]) HAVE_LOG10L=1; AC_SUBST([HAVE_LOG10L]) HAVE_LOG1P=1; AC_SUBST([HAVE_LOG1P]) + HAVE_LOG1PF=1; AC_SUBST([HAVE_LOG1PF]) HAVE_MODFF=1; AC_SUBST([HAVE_MODFF]) HAVE_MODFL=1; AC_SUBST([HAVE_MODFL]) HAVE_POWF=1; AC_SUBST([HAVE_POWF]) @@ -265,6 +268,7 @@ AC_DEFUN([gl_MATH_H_DEFAULTS], REPLACE_LOG=0; AC_SUBST([REPLACE_LOG]) REPLACE_LOGF=0; AC_SUBST([REPLACE_LOGF]) REPLACE_LOGL=0; AC_SUBST([REPLACE_LOGL]) + REPLACE_LOG1PF=0; AC_SUBST([REPLACE_LOG1PF]) REPLACE_MODF=0; AC_SUBST([REPLACE_MODF]) REPLACE_MODFF=0; AC_SUBST([REPLACE_MODFF]) REPLACE_MODFL=0; AC_SUBST([REPLACE_MODFL]) diff --git a/modules/log1pf b/modules/log1pf new file mode 100644 index 000000000..10a7a8d20 --- /dev/null +++ b/modules/log1pf @@ -0,0 +1,32 @@ +Description: +log1pf() function: natural logarithm of 1 plus argument. + +Files: +lib/log1pf.c +m4/log1pf.m4 + +Depends-on: +math +extensions +log1p [test $HAVE_LOG1PF = 0 || test $REPLACE_LOG1PF = 1] + +configure.ac: +gl_FUNC_LOG1PF +if test $HAVE_LOG1PF = 0 || test $REPLACE_LOG1PF = 1; then + AC_LIBOBJ([log1pf]) +fi +gl_MATH_MODULE_INDICATOR([log1pf]) + +Makefile.am: + +Include: + + +Link: +$(LOG1PF_LIBM) + +License: +LGPL + +Maintainer: +Bruno Haible diff --git a/modules/math b/modules/math index 6c46eb0c2..836260771 100644 --- a/modules/math +++ b/modules/math @@ -87,6 +87,7 @@ math.h: math.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(ARG_NONNULL_H) $( -e 's/@''GNULIB_LOG10F''@/$(GNULIB_LOG10F)/g' \ -e 's/@''GNULIB_LOG10L''@/$(GNULIB_LOG10L)/g' \ -e 's/@''GNULIB_LOG1P''@/$(GNULIB_LOG1P)/g' \ + -e 's/@''GNULIB_LOG1PF''@/$(GNULIB_LOG1PF)/g' \ -e 's/@''GNULIB_MODF''@/$(GNULIB_MODF)/g' \ -e 's/@''GNULIB_MODFF''@/$(GNULIB_MODFF)/g' \ -e 's/@''GNULIB_MODFL''@/$(GNULIB_MODFL)/g' \ @@ -151,6 +152,7 @@ math.h: math.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(ARG_NONNULL_H) $( -e 's|@''HAVE_LOG10F''@|$(HAVE_LOG10F)|g' \ -e 's|@''HAVE_LOG10L''@|$(HAVE_LOG10L)|g' \ -e 's|@''HAVE_LOG1P''@|$(HAVE_LOG1P)|g' \ + -e 's|@''HAVE_LOG1PF''@|$(HAVE_LOG1PF)|g' \ -e 's|@''HAVE_MODFF''@|$(HAVE_MODFF)|g' \ -e 's|@''HAVE_MODFL''@|$(HAVE_MODFL)|g' \ -e 's|@''HAVE_POWF''@|$(HAVE_POWF)|g' \ @@ -234,6 +236,7 @@ math.h: math.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(ARG_NONNULL_H) $( -e 's|@''REPLACE_LOG''@|$(REPLACE_LOG)|g' \ -e 's|@''REPLACE_LOGF''@|$(REPLACE_LOGF)|g' \ -e 's|@''REPLACE_LOGL''@|$(REPLACE_LOGL)|g' \ + -e 's|@''REPLACE_LOG1PF''@|$(REPLACE_LOG1PF)|g' \ -e 's|@''REPLACE_MODF''@|$(REPLACE_MODF)|g' \ -e 's|@''REPLACE_MODFF''@|$(REPLACE_MODFF)|g' \ -e 's|@''REPLACE_MODFL''@|$(REPLACE_MODFL)|g' \ diff --git a/tests/test-math-c++.cc b/tests/test-math-c++.cc index 3b25714f4..6b3c299c0 100644 --- a/tests/test-math-c++.cc +++ b/tests/test-math-c++.cc @@ -215,6 +215,9 @@ SIGNATURE_CHECK (GNULIB_NAMESPACE::ldexpl, long double, (long double, int)); SIGNATURE_CHECK (GNULIB_NAMESPACE::log10l, long double, (long double)); #endif +#if GNULIB_TEST_LOG1PF +SIGNATURE_CHECK (GNULIB_NAMESPACE::log1pf, float, (float)); +#endif #if GNULIB_TEST_LOG1P SIGNATURE_CHECK (GNULIB_NAMESPACE::log1p, double, (double)); #endif -- 2.11.0