From b398592c340a33c50703310c3df0d50ed777fe0d Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Sat, 8 Oct 2011 22:45:54 +0200 Subject: [PATCH] New module 'powf'. * lib/math.in.h (powf): New declaration. * lib/powf.c: New file. * m4/powf.m4: New file. * m4/math_h.m4 (gl_MATH_H): Test whether powf is declared. (gl_MATH_H_DEFAULTS): Initialize GNULIB_POWF, HAVE_POWF. * modules/math (Makefile.am): Substitute GNULIB_POWF, HAVE_POWF. * modules/powf: New file. * tests/test-math-c++.cc: Check the declaration of powf. * doc/posix-functions/powf.texi: Mention the new module. --- ChangeLog | 11 +++++++++++ doc/posix-functions/powf.texi | 10 +++++----- lib/math.in.h | 16 ++++++++++++++++ lib/powf.c | 26 ++++++++++++++++++++++++++ m4/math_h.m4 | 6 ++++-- m4/powf.m4 | 25 +++++++++++++++++++++++++ modules/math | 2 ++ modules/powf | 31 +++++++++++++++++++++++++++++++ tests/test-math-c++.cc | 3 +++ 9 files changed, 123 insertions(+), 7 deletions(-) create mode 100644 lib/powf.c create mode 100644 m4/powf.m4 create mode 100644 modules/powf diff --git a/ChangeLog b/ChangeLog index c74481529..3ce94fadc 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,16 @@ 2011-10-08 Bruno Haible + New module 'powf'. + * lib/math.in.h (powf): New declaration. + * lib/powf.c: New file. + * m4/powf.m4: New file. + * m4/math_h.m4 (gl_MATH_H): Test whether powf is declared. + (gl_MATH_H_DEFAULTS): Initialize GNULIB_POWF, HAVE_POWF. + * modules/math (Makefile.am): Substitute GNULIB_POWF, HAVE_POWF. + * modules/powf: New file. + * tests/test-math-c++.cc: Check the declaration of powf. + * doc/posix-functions/powf.texi: Mention the new module. + pow: Use a .m4 file. * m4/pow.m4: New file. * modules/pow (Files): Add it. diff --git a/doc/posix-functions/powf.texi b/doc/posix-functions/powf.texi index 7b79f78c6..a3a6b5150 100644 --- a/doc/posix-functions/powf.texi +++ b/doc/posix-functions/powf.texi @@ -4,14 +4,10 @@ POSIX specification:@* @url{http://www.opengroup.org/onlinepubs/9699919799/functions/powf.html} -Gnulib module: --- +Gnulib module: powf 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, Solaris 9. @@ -19,3 +15,7 @@ Minix 3.1.8, AIX 5.1, Solaris 9. 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/math.in.h b/lib/math.in.h index 4a868559a..c2ea02386 100644 --- a/lib/math.in.h +++ b/lib/math.in.h @@ -561,6 +561,22 @@ _GL_WARN_ON_USE (modff, "modff is unportable - " #endif +#if @GNULIB_POWF@ +# if !@HAVE_POWF@ +# undef powf +_GL_FUNCDECL_SYS (powf, float, (float x, float y)); +# endif +_GL_CXXALIAS_SYS (powf, float, (float x, float y)); +_GL_CXXALIASWARN (powf); +#elif defined GNULIB_POSIXCHECK +# undef powf +# if HAVE_RAW_DECL_POWF +_GL_WARN_ON_USE (powf, "powf is unportable - " + "use gnulib module powf for portability"); +# endif +#endif + + #if @GNULIB_ROUNDF@ # if @REPLACE_ROUNDF@ # if !(defined __cplusplus && defined GNULIB_NAMESPACE) diff --git a/lib/powf.c b/lib/powf.c new file mode 100644 index 000000000..d5a81b9be --- /dev/null +++ b/lib/powf.c @@ -0,0 +1,26 @@ +/* Power function. + 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 + +float +powf (float x, float y) +{ + return (float) pow ((double) x, (double) y); +} diff --git a/m4/math_h.m4 b/m4/math_h.m4 index a8044f195..4c47bd79d 100644 --- a/m4/math_h.m4 +++ b/m4/math_h.m4 @@ -1,4 +1,4 @@ -# math_h.m4 serial 35 +# math_h.m4 serial 36 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 ]], [acosl asinl atanl ceilf ceill cosl expf expl fabsf floorf floorl fmodf frexpf frexpl - ldexpf ldexpl logb logf logl log10f modff + ldexpf ldexpl logb logf logl log10f modff powf round roundf roundl sinl sqrtf sqrtl tanl trunc truncf truncl]) ]) @@ -87,6 +87,7 @@ AC_DEFUN([gl_MATH_H_DEFAULTS], GNULIB_LOGL=0; AC_SUBST([GNULIB_LOGL]) GNULIB_LOG10F=0; AC_SUBST([GNULIB_LOG10F]) GNULIB_MODFF=0; AC_SUBST([GNULIB_MODFF]) + GNULIB_POWF=0; AC_SUBST([GNULIB_POWF]) GNULIB_ROUND=0; AC_SUBST([GNULIB_ROUND]) GNULIB_ROUNDF=0; AC_SUBST([GNULIB_ROUNDF]) GNULIB_ROUNDL=0; AC_SUBST([GNULIB_ROUNDL]) @@ -116,6 +117,7 @@ AC_DEFUN([gl_MATH_H_DEFAULTS], HAVE_LOGL=1; AC_SUBST([HAVE_LOGL]) HAVE_LOG10F=1; AC_SUBST([HAVE_LOG10F]) HAVE_MODFF=1; AC_SUBST([HAVE_MODFF]) + HAVE_POWF=1; AC_SUBST([HAVE_POWF]) HAVE_SINL=1; AC_SUBST([HAVE_SINL]) HAVE_SQRTF=1; AC_SUBST([HAVE_SQRTF]) HAVE_SQRTL=1; AC_SUBST([HAVE_SQRTL]) diff --git a/m4/powf.m4 b/m4/powf.m4 new file mode 100644 index 000000000..947573ebe --- /dev/null +++ b/m4/powf.m4 @@ -0,0 +1,25 @@ +# powf.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_POWF], +[ + AC_REQUIRE([gl_MATH_H_DEFAULTS]) + AC_REQUIRE([gl_FUNC_POW]) + + dnl Test whether powf() exists. Assume that powf(), if it exists, is + dnl defined in the same library as pow(). + save_LIBS="$LIBS" + LIBS="$LIBS $POW_LIBM" + AC_CHECK_FUNCS([powf]) + LIBS="$save_LIBS" + if test $ac_cv_func_powf = yes; then + POWF_LIBM="$POW_LIBM" + else + HAVE_POWF=0 + POWF_LIBM="$POW_LIBM" + fi + AC_SUBST([POWF_LIBM]) +]) diff --git a/modules/math b/modules/math index 9f2b22946..230279449 100644 --- a/modules/math +++ b/modules/math @@ -58,6 +58,7 @@ math.h: math.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(ARG_NONNULL_H) $( -e 's/@''GNULIB_LOGL''@/$(GNULIB_LOGL)/g' \ -e 's/@''GNULIB_LOG10F''@/$(GNULIB_LOG10F)/g' \ -e 's/@''GNULIB_MODFF''@/$(GNULIB_MODFF)/g' \ + -e 's/@''GNULIB_POWF''@/$(GNULIB_POWF)/g' \ -e 's/@''GNULIB_ROUND''@/$(GNULIB_ROUND)/g' \ -e 's/@''GNULIB_ROUNDF''@/$(GNULIB_ROUNDF)/g' \ -e 's/@''GNULIB_ROUNDL''@/$(GNULIB_ROUNDL)/g' \ @@ -87,6 +88,7 @@ math.h: math.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(ARG_NONNULL_H) $( -e 's|@''HAVE_LOGL''@|$(HAVE_LOGL)|g' \ -e 's|@''HAVE_LOG10F''@|$(HAVE_LOG10F)|g' \ -e 's|@''HAVE_MODFF''@|$(HAVE_MODFF)|g' \ + -e 's|@''HAVE_POWF''@|$(HAVE_POWF)|g' \ -e 's|@''HAVE_SINL''@|$(HAVE_SINL)|g' \ -e 's|@''HAVE_SQRTF''@|$(HAVE_SQRTF)|g' \ -e 's|@''HAVE_SQRTL''@|$(HAVE_SQRTL)|g' \ diff --git a/modules/powf b/modules/powf new file mode 100644 index 000000000..0f31ce2cf --- /dev/null +++ b/modules/powf @@ -0,0 +1,31 @@ +Description: +powf() function: power function. + +Files: +lib/powf.c +m4/powf.m4 + +Depends-on: +math +pow [test $HAVE_POWF = 0] + +configure.ac: +gl_FUNC_POWF +if test $HAVE_POWF = 0; then + AC_LIBOBJ([powf]) +fi +gl_MATH_MODULE_INDICATOR([powf]) + +Makefile.am: + +Include: + + +Link: +$(POWF_LIBM) + +License: +LGPL + +Maintainer: +Bruno Haible diff --git a/tests/test-math-c++.cc b/tests/test-math-c++.cc index 67d7f71c0..e93f4d9bb 100644 --- a/tests/test-math-c++.cc +++ b/tests/test-math-c++.cc @@ -76,6 +76,9 @@ SIGNATURE_CHECK (GNULIB_NAMESPACE::modff, float, (float, float *)); #endif //SIGNATURE_CHECK (GNULIB_NAMESPACE::modf, double, (double, double *)); //SIGNATURE_CHECK (GNULIB_NAMESPACE::nextafter, double, (double, double)); +#if GNULIB_TEST_POWF +SIGNATURE_CHECK (GNULIB_NAMESPACE::powf, float, (float, float)); +#endif //SIGNATURE_CHECK (GNULIB_NAMESPACE::pow, double, (double, double)); //SIGNATURE_CHECK (GNULIB_NAMESPACE::remainder, double, (double, double)); //SIGNATURE_CHECK (GNULIB_NAMESPACE::rint, double, (double)); -- 2.11.0