# HG changeset patch # User Bruno Haible # Date 1317979078 -7200 # Node ID cd98f212217ec2ed04d98827e8212999f74637bc # Parent 76230af5e5b8516dc3c1ff49cb5723d885842e38 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. diff --git a/ChangeLog b/ChangeLog --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,16 @@ +2011-10-07 Bruno Haible + + 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 frexpf: Work around problems on IRIX and mingw. diff --git a/doc/posix-functions/ldexpf.texi b/doc/posix-functions/ldexpf.texi --- 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 diff --git a/lib/ldexpf.c b/lib/ldexpf.c 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 . */ + +#include + +/* Specification. */ +#include + +/* 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 --- 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 diff --git a/m4/ldexpf.m4 b/m4/ldexpf.m4 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]) +]) diff --git a/m4/math_h.m4 b/m4/math_h.m4 --- 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 ]], [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]) diff --git a/modules/ldexpf b/modules/ldexpf 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: + + +Link: +$(LDEXPF_LIBM) + +License: +LGPL + +Maintainer: +Bruno Haible diff --git a/modules/math b/modules/math --- 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' \ diff --git a/tests/test-math-c++.cc b/tests/test-math-c++.cc --- 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));