changeset 15847:cd98f212217e

New module 'ldexpf'. * lib/math.in.h (ldexpf): New declaration. * lib/ldexpf.c: New file. * m4/ldexpf.m4: New file. * m4/math_h.m4 (gl_MATH_H): Test whether ldexpf is declared. (gl_MATH_H_DEFAULTS): Initialize GNULIB_LDEXPF, HAVE_LDEXPF. * modules/math (Makefile.am): Substitute GNULIB_LDEXPF, HAVE_LDEXPF. * modules/ldexpf: New file. * tests/test-math-c++.cc: Check the declaration of ldexpf. * doc/posix-functions/ldexpf.texi: Mention the new module.
author Bruno Haible <bruno@clisp.org>
date Fri, 07 Oct 2011 11:17:58 +0200
parents 76230af5e5b8
children 0dd7e4732abc
files ChangeLog doc/posix-functions/ldexpf.texi lib/ldexpf.c lib/math.in.h m4/ldexpf.m4 m4/math_h.m4 modules/ldexpf modules/math tests/test-math-c++.cc
diffstat 9 files changed, 130 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,16 @@
+2011-10-07  Bruno Haible  <bruno@clisp.org>
+
+	New module 'ldexpf'.
+	* lib/math.in.h (ldexpf): New declaration.
+	* lib/ldexpf.c: New file.
+	* m4/ldexpf.m4: New file.
+	* m4/math_h.m4 (gl_MATH_H): Test whether ldexpf is declared.
+	(gl_MATH_H_DEFAULTS): Initialize GNULIB_LDEXPF, HAVE_LDEXPF.
+	* modules/math (Makefile.am): Substitute GNULIB_LDEXPF, HAVE_LDEXPF.
+	* modules/ldexpf: New file.
+	* tests/test-math-c++.cc: Check the declaration of ldexpf.
+	* doc/posix-functions/ldexpf.texi: Mention the new module.
+
 2011-10-06  Bruno Haible  <bruno@clisp.org>
 
 	frexpf: Work around problems on IRIX and mingw.
--- a/doc/posix-functions/ldexpf.texi
+++ b/doc/posix-functions/ldexpf.texi
@@ -4,18 +4,18 @@
 
 POSIX specification:@* @url{http://www.opengroup.org/onlinepubs/9699919799/functions/ldexpf.html}
 
-Gnulib module: ---
+Gnulib module: ldexpf
 
 Portability problems fixed by Gnulib:
 @itemize
+@item
+This function is missing on some platforms:
+Minix 3.1.8, AIX 5.1, HP-UX 11, older IRIX 6.5, Solaris 9.
+@item
+This function is only defined as a macro with arguments on some platforms:
+MSVC 9.
 @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, IRIX 6.5, Solaris 9.
-@item
-This function is only defined as a macro with arguments on some platforms:
-MSVC 9.
 @end itemize
new file mode 100644
--- /dev/null
+++ b/lib/ldexpf.c
@@ -0,0 +1,31 @@
+/* Multiply a 'float' by a power of 2.
+   Copyright (C) 2011 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>
+
+/* Avoid some warnings from "gcc -Wshadow".
+   This file doesn't use the exp() function.  */
+#undef exp
+#define exp exponent
+
+float
+ldexpf (float x, int exp)
+{
+  return (float) ldexp ((double) x, exp);
+}
--- a/lib/math.in.h
+++ b/lib/math.in.h
@@ -428,6 +428,22 @@
 
 
 /* Return x * 2^exp.  */
+#if @GNULIB_LDEXPF@
+# if !@HAVE_LDEXPF@
+#  undef ldexpf
+_GL_FUNCDECL_SYS (ldexpf, float, (float x, int exp));
+# endif
+_GL_CXXALIAS_SYS (ldexpf, float, (float x, int exp));
+_GL_CXXALIASWARN (ldexpf);
+#elif defined GNULIB_POSIXCHECK
+# undef ldexpf
+# if HAVE_RAW_DECL_LDEXPF
+_GL_WARN_ON_USE (ldexpf, "ldexpf is unportable - "
+                 "use gnulib module ldexpf for portability");
+# endif
+#endif
+
+/* Return x * 2^exp.  */
 #if @GNULIB_LDEXPL@ && @REPLACE_LDEXPL@
 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
 #  undef ldexpl
new file mode 100644
--- /dev/null
+++ b/m4/ldexpf.m4
@@ -0,0 +1,22 @@
+# ldexpf.m4 serial 1
+dnl Copyright (C) 2011 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_LDEXPF],
+[
+  AC_REQUIRE([gl_MATH_H_DEFAULTS])
+  AC_REQUIRE([gl_FUNC_LDEXP])
+
+  dnl Test whether ldexpf() exists. We cannot assume that ldexpf(), if it
+  dnl exists, is defined in the same library as ldexp(). This is not the case
+  dnl on FreeBSD, NetBSD, OpenBSD.
+  gl_MATHFUNC([ldexpf], [float], [(float, int)])
+  if test $gl_cv_func_ldexpf_no_libm = no \
+     && test $gl_cv_func_ldexpf_in_libm = no; then
+    HAVE_LDEXPF=0
+    LDEXPF_LIBM="$LDEXP_LIBM"
+  fi
+  AC_SUBST([LDEXPF_LIBM])
+])
--- a/m4/math_h.m4
+++ b/m4/math_h.m4
@@ -1,4 +1,4 @@
-# math_h.m4 serial 30
+# math_h.m4 serial 31
 dnl Copyright (C) 2007-2011 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -41,7 +41,7 @@
   gl_WARN_ON_USE_PREPARE([[#include <math.h>]],
     [acosl asinl atanl ceilf ceill cosl expl fabsf floorf floorl fmodf
      frexpf frexpl
-     ldexpl logb logl modff round roundf roundl sinl sqrtl
+     ldexpf ldexpl logb logl modff round roundf roundl sinl sqrtl
      tanl trunc truncf truncl])
 ])
 
@@ -78,6 +78,7 @@
   GNULIB_ISNANF=0;   AC_SUBST([GNULIB_ISNANF])
   GNULIB_ISNAND=0;   AC_SUBST([GNULIB_ISNAND])
   GNULIB_ISNANL=0;   AC_SUBST([GNULIB_ISNANL])
+  GNULIB_LDEXPF=0;   AC_SUBST([GNULIB_LDEXPF])
   GNULIB_LDEXPL=0;   AC_SUBST([GNULIB_LDEXPL])
   GNULIB_LOGB=0;     AC_SUBST([GNULIB_LOGB])
   GNULIB_LOGL=0;     AC_SUBST([GNULIB_LOGL])
@@ -104,6 +105,7 @@
   HAVE_ISNANF=1;               AC_SUBST([HAVE_ISNANF])
   HAVE_ISNAND=1;               AC_SUBST([HAVE_ISNAND])
   HAVE_ISNANL=1;               AC_SUBST([HAVE_ISNANL])
+  HAVE_LDEXPF=1;               AC_SUBST([HAVE_LDEXPF])
   HAVE_LOGL=1;                 AC_SUBST([HAVE_LOGL])
   HAVE_MODFF=1;                AC_SUBST([HAVE_MODFF])
   HAVE_SINL=1;                 AC_SUBST([HAVE_SINL])
new file mode 100644
--- /dev/null
+++ b/modules/ldexpf
@@ -0,0 +1,32 @@
+Description:
+ldexpf() function: multiply a 'float' by a power of 2.
+
+Files:
+lib/ldexpf.c
+m4/ldexpf.m4
+m4/mathfunc.m4
+
+Depends-on:
+math
+ldexp           [test $HAVE_LDEXPF = 0]
+
+configure.ac:
+gl_FUNC_LDEXPF
+if test $HAVE_LDEXPF = 0; then
+  AC_LIBOBJ([ldexpf])
+fi
+gl_MATH_MODULE_INDICATOR([ldexpf])
+
+Makefile.am:
+
+Include:
+<math.h>
+
+Link:
+$(LDEXPF_LIBM)
+
+License:
+LGPL
+
+Maintainer:
+Bruno Haible
--- a/modules/math
+++ b/modules/math
@@ -50,6 +50,7 @@
 	      -e 's/@''GNULIB_ISNANF''@/$(GNULIB_ISNANF)/g' \
 	      -e 's/@''GNULIB_ISNAND''@/$(GNULIB_ISNAND)/g' \
 	      -e 's/@''GNULIB_ISNANL''@/$(GNULIB_ISNANL)/g' \
+	      -e 's/@''GNULIB_LDEXPF''@/$(GNULIB_LDEXPF)/g' \
 	      -e 's/@''GNULIB_LDEXPL''@/$(GNULIB_LDEXPL)/g' \
 	      -e 's/@''GNULIB_LOGB''@/$(GNULIB_LOGB)/g' \
 	      -e 's/@''GNULIB_LOGL''@/$(GNULIB_LOGL)/g' \
@@ -76,6 +77,7 @@
 	      -e 's|@''HAVE_ISNANF''@|$(HAVE_ISNANF)|g' \
 	      -e 's|@''HAVE_ISNAND''@|$(HAVE_ISNAND)|g' \
 	      -e 's|@''HAVE_ISNANL''@|$(HAVE_ISNANL)|g' \
+	      -e 's|@''HAVE_LDEXPF''@|$(HAVE_LDEXPF)|g' \
 	      -e 's|@''HAVE_LOGL''@|$(HAVE_LOGL)|g' \
 	      -e 's|@''HAVE_MODFF''@|$(HAVE_MODFF)|g' \
 	      -e 's|@''HAVE_SINL''@|$(HAVE_SINL)|g' \
--- a/tests/test-math-c++.cc
+++ b/tests/test-math-c++.cc
@@ -53,6 +53,9 @@
 //SIGNATURE_CHECK (GNULIB_NAMESPACE::j0, double, (double));
 //SIGNATURE_CHECK (GNULIB_NAMESPACE::j1, double, (double));
 //SIGNATURE_CHECK (GNULIB_NAMESPACE::jn, double, (int, double));
+#if GNULIB_TEST_LDEXPF
+SIGNATURE_CHECK (GNULIB_NAMESPACE::ldexpf, float, (float, int));
+#endif
 //SIGNATURE_CHECK (GNULIB_NAMESPACE::ldexp, double, (double, int));
 //SIGNATURE_CHECK (GNULIB_NAMESPACE::lgamma, double, (double));
 //SIGNATURE_CHECK (GNULIB_NAMESPACE::log10, double, (double));