New module 'log1pf'.
authorBruno Haible <bruno@clisp.org>
Sat, 10 Mar 2012 21:28:49 +0000 (22:28 +0100)
committerBruno Haible <bruno@clisp.org>
Sun, 11 Mar 2012 01:40:32 +0000 (02:40 +0100)
* 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
doc/posix-functions/log1pf.texi
lib/log1pf.c [new file with mode: 0644]
lib/math.in.h
m4/log1pf.m4 [new file with mode: 0644]
m4/math_h.m4
modules/log1pf [new file with mode: 0644]
modules/math
tests/test-math-c++.cc

index b8ed3e0..39e3ddc 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,20 @@
 2012-03-10  Bruno Haible  <bruno@clisp.org>
 
+       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  <bruno@clisp.org>
+
        log1p tests: More tests.
        * tests/test-log1p.h: New file.
        * modules/log1p-tests (Files): Add tests/test-log1p.h, tests/randomd.c.
index d5c8486..2e3c49a 100644 (file)
@@ -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 (file)
index 0000000..4d889fa
--- /dev/null
@@ -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 <http://www.gnu.org/licenses/>.  */
+
+#include <config.h>
+
+/* Specification.  */
+#include <math.h>
+
+float
+log1pf (float x)
+{
+  return (float) log1p ((double) x);
+}
index a479b6d..9f7147d 100644 (file)
@@ -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 (file)
index 0000000..b012433
--- /dev/null
@@ -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 <math.h> 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 <math.h>
+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
+        ])
+    ])
+])
index 028d8cd..8290c16 100644 (file)
@@ -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 (file)
index 0000000..10a7a8d
--- /dev/null
@@ -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:
+<math.h>
+
+Link:
+$(LOG1PF_LIBM)
+
+License:
+LGPL
+
+Maintainer:
+Bruno Haible
index 6c46eb0..8362607 100644 (file)
@@ -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' \
index 3b25714..6b3c299 100644 (file)
@@ -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