New module 'ldexpf'.
authorBruno Haible <bruno@clisp.org>
Fri, 7 Oct 2011 09:17:58 +0000 (11:17 +0200)
committerBruno Haible <bruno@clisp.org>
Fri, 7 Oct 2011 09:17:58 +0000 (11:17 +0200)
* 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.

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

index bb0fb14..cdde4ab 100644 (file)
--- 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.
index c5331fa..252b279 100644 (file)
@@ -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
-@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.
+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
+@end itemize
diff --git a/lib/ldexpf.c b/lib/ldexpf.c
new file mode 100644 (file)
index 0000000..0460d1a
--- /dev/null
@@ -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);
+}
index 2e65f70..a80f24f 100644 (file)
@@ -428,6 +428,22 @@ _GL_WARN_ON_USE (frexpl, "frexpl is unportable - "
 
 
 /* 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
diff --git a/m4/ldexpf.m4 b/m4/ldexpf.m4
new file mode 100644 (file)
index 0000000..eaafdc5
--- /dev/null
@@ -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])
+])
index b78b718..6ba9448 100644 (file)
@@ -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 @@ AC_DEFUN([gl_MATH_H],
   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 @@ AC_DEFUN([gl_MATH_H_DEFAULTS],
   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 @@ AC_DEFUN([gl_MATH_H_DEFAULTS],
   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])
diff --git a/modules/ldexpf b/modules/ldexpf
new file mode 100644 (file)
index 0000000..3c1f15c
--- /dev/null
@@ -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
index e645cfb..6d8da2e 100644 (file)
@@ -50,6 +50,7 @@ math.h: math.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(ARG_NONNULL_H) $(
              -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 @@ math.h: math.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(ARG_NONNULL_H) $(
              -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' \
index 8b2e970..25b7697 100644 (file)
@@ -53,6 +53,9 @@ SIGNATURE_CHECK (GNULIB_NAMESPACE::frexp, double, (double, int *));
 //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));