summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBruno Haible <bruno@clisp.org>2011-10-07 11:17:58 +0200
committerBruno Haible <bruno@clisp.org>2011-10-07 11:17:58 +0200
commite677143bef643fc74c206d19a7f8767745ba8774 (patch)
tree0e3fdeacc837f6ce10c7eaf5cc33187b4d90592a
parent64f8702c4e327806f329b7f46f7a1796032b2111 (diff)
downloadgnulib-e677143bef643fc74c206d19a7f8767745ba8774.tar.gz
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.
-rw-r--r--ChangeLog13
-rw-r--r--doc/posix-functions/ldexpf.texi12
-rw-r--r--lib/ldexpf.c31
-rw-r--r--lib/math.in.h16
-rw-r--r--m4/ldexpf.m422
-rw-r--r--m4/math_h.m46
-rw-r--r--modules/ldexpf32
-rw-r--r--modules/math2
-rw-r--r--tests/test-math-c++.cc3
9 files changed, 129 insertions, 8 deletions
diff --git a/ChangeLog b/ChangeLog
index bb0fb14952..cdde4ab892 100644
--- 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.
diff --git a/doc/posix-functions/ldexpf.texi b/doc/posix-functions/ldexpf.texi
index c5331fa389..252b279b26 100644
--- 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
-@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
index 0000000000..0460d1a0ae
--- /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);
+}
diff --git a/lib/math.in.h b/lib/math.in.h
index 2e65f70661..a80f24f6c5 100644
--- a/lib/math.in.h
+++ b/lib/math.in.h
@@ -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
index 0000000000..eaafdc5284
--- /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])
+])
diff --git a/m4/math_h.m4 b/m4/math_h.m4
index b78b71863a..6ba94489e3 100644
--- 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 @@ 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
index 0000000000..3c1f15c694
--- /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
diff --git a/modules/math b/modules/math
index e645cfbbfc..6d8da2ed9f 100644
--- a/modules/math
+++ b/modules/math
@@ -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' \
diff --git a/tests/test-math-c++.cc b/tests/test-math-c++.cc
index 8b2e970a8f..25b7697a13 100644
--- a/tests/test-math-c++.cc
+++ b/tests/test-math-c++.cc
@@ -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));