From 7f26f4f75fc3aee7a5e351ecdf05278d9890ff3e Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Thu, 6 Oct 2011 00:03:44 +0200 Subject: [PATCH] New module 'fabsf'. * lib/math.in.h (fabsf): New declaration. * lib/fabsf.c: New file. * m4/fabsf.m4: New file. * m4/math_h.m4 (gl_MATH_H_DEFAULTS): Initialize GNULIB_FABSF, HAVE_FABSF. * modules/math (Makefile.am): Substitute GNULIB_FABSF, HAVE_FABSF. * modules/fabsf: New file. * tests/test-math-c++.cc: Check the declaration of fabsf. * doc/posix-functions/fabsf.texi: Mention the new module. --- ChangeLog | 11 +++++++++++ doc/posix-functions/fabsf.texi | 10 +++++----- lib/fabsf.c | 26 ++++++++++++++++++++++++++ lib/math.in.h | 16 ++++++++++++++++ m4/fabsf.m4 | 25 +++++++++++++++++++++++++ m4/math_h.m4 | 4 +++- modules/fabsf | 31 +++++++++++++++++++++++++++++++ modules/math | 2 ++ tests/test-math-c++.cc | 3 +++ 9 files changed, 122 insertions(+), 6 deletions(-) create mode 100644 lib/fabsf.c create mode 100644 m4/fabsf.m4 create mode 100644 modules/fabsf diff --git a/ChangeLog b/ChangeLog index cccd6f625..8c5b96eb2 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,16 @@ 2011-10-05 Bruno Haible + New module 'fabsf'. + * lib/math.in.h (fabsf): New declaration. + * lib/fabsf.c: New file. + * m4/fabsf.m4: New file. + * m4/math_h.m4 (gl_MATH_H_DEFAULTS): Initialize GNULIB_FABSF, + HAVE_FABSF. + * modules/math (Makefile.am): Substitute GNULIB_FABSF, HAVE_FABSF. + * modules/fabsf: New file. + * tests/test-math-c++.cc: Check the declaration of fabsf. + * doc/posix-functions/fabsf.texi: Mention the new module. + fabs: Use a .m4 file. * m4/fabs.m4: New file. * modules/fabs (Files): Add it. diff --git a/doc/posix-functions/fabsf.texi b/doc/posix-functions/fabsf.texi index 87d853825..4f6372494 100644 --- a/doc/posix-functions/fabsf.texi +++ b/doc/posix-functions/fabsf.texi @@ -4,14 +4,10 @@ POSIX specification:@* @url{http://www.opengroup.org/onlinepubs/9699919799/functions/fabsf.html} -Gnulib module: --- +Gnulib module: fabsf Portability problems fixed by Gnulib: @itemize -@end itemize - -Portability problems not fixed by Gnulib: -@itemize @item This function is missing on some platforms: AIX 5.1, Solaris 9. @@ -19,3 +15,7 @@ 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/fabsf.c b/lib/fabsf.c new file mode 100644 index 000000000..4c0f970fd --- /dev/null +++ b/lib/fabsf.c @@ -0,0 +1,26 @@ +/* Absolute value. + 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 +fabsf (float x) +{ + return (float) fabs ((double) x); +} diff --git a/lib/math.in.h b/lib/math.in.h index f82d03c2f..73ad15d50 100644 --- a/lib/math.in.h +++ b/lib/math.in.h @@ -282,6 +282,22 @@ _GL_WARN_ON_USE (expl, "expl is unportable - " #endif +#if @GNULIB_FABSF@ +# if !@HAVE_FABSF@ +# undef fabsf +_GL_FUNCDECL_SYS (fabsf, float, (float x)); +# endif +_GL_CXXALIAS_SYS (fabsf, float, (float x)); +_GL_CXXALIASWARN (fabsf); +#elif defined GNULIB_POSIXCHECK +# undef fabsf +# if HAVE_RAW_DECL_FABSF +_GL_WARN_ON_USE (fabsf, "fabsf is unportable - " + "use gnulib module fabsf for portability"); +# endif +#endif + + #if @GNULIB_FLOORF@ # if @REPLACE_FLOORF@ # if !(defined __cplusplus && defined GNULIB_NAMESPACE) diff --git a/m4/fabsf.m4 b/m4/fabsf.m4 new file mode 100644 index 000000000..792475813 --- /dev/null +++ b/m4/fabsf.m4 @@ -0,0 +1,25 @@ +# fabsf.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_FABSF], +[ + AC_REQUIRE([gl_MATH_H_DEFAULTS]) + AC_REQUIRE([gl_FUNC_FABS]) + + dnl Test whether fabsf() exists. Assume that fabsf(), if it exists, is + dnl defined in the same library as fabs(). + save_LIBS="$LIBS" + LIBS="$LIBS $FABS_LIBM" + AC_CHECK_FUNCS([fabsf]) + LIBS="$save_LIBS" + if test $ac_cv_func_fabsf = yes; then + FABSF_LIBM="$FABS_LIBM" + else + HAVE_FABSF=0 + FABSF_LIBM="$FABS_LIBM" + fi + AC_SUBST([FABSF_LIBM]) +]) diff --git a/m4/math_h.m4 b/m4/math_h.m4 index 7b46aeef8..50f2a8f81 100644 --- a/m4/math_h.m4 +++ b/m4/math_h.m4 @@ -1,4 +1,4 @@ -# math_h.m4 serial 25 +# math_h.m4 serial 26 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, @@ -62,6 +62,7 @@ AC_DEFUN([gl_MATH_H_DEFAULTS], GNULIB_CEILL=0; AC_SUBST([GNULIB_CEILL]) GNULIB_COSL=0; AC_SUBST([GNULIB_COSL]) GNULIB_EXPL=0; AC_SUBST([GNULIB_EXPL]) + GNULIB_FABSF=0; AC_SUBST([GNULIB_FABSF]) GNULIB_FLOOR=0; AC_SUBST([GNULIB_FLOOR]) GNULIB_FLOORF=0; AC_SUBST([GNULIB_FLOORF]) GNULIB_FLOORL=0; AC_SUBST([GNULIB_FLOORL]) @@ -92,6 +93,7 @@ AC_DEFUN([gl_MATH_H_DEFAULTS], HAVE_ATANL=1; AC_SUBST([HAVE_ATANL]) HAVE_COSL=1; AC_SUBST([HAVE_COSL]) HAVE_EXPL=1; AC_SUBST([HAVE_EXPL]) + HAVE_FABSF=1; AC_SUBST([HAVE_FABSF]) HAVE_ISNANF=1; AC_SUBST([HAVE_ISNANF]) HAVE_ISNAND=1; AC_SUBST([HAVE_ISNAND]) HAVE_ISNANL=1; AC_SUBST([HAVE_ISNANL]) diff --git a/modules/fabsf b/modules/fabsf new file mode 100644 index 000000000..c3cafda09 --- /dev/null +++ b/modules/fabsf @@ -0,0 +1,31 @@ +Description: +fabsf() function: absolute value. + +Files: +lib/fabsf.c +m4/fabsf.m4 + +Depends-on: +math +fabs [test $HAVE_FABSF = 0] + +configure.ac: +gl_FUNC_FABSF +if test $HAVE_FABSF = 0; then + AC_LIBOBJ([fabsf]) +fi +gl_MATH_MODULE_INDICATOR([fabsf]) + +Makefile.am: + +Include: + + +Link: +$(FABSF_LIBM) + +License: +LGPL + +Maintainer: +Bruno Haible diff --git a/modules/math b/modules/math index 8062d2da5..73833ef54 100644 --- a/modules/math +++ b/modules/math @@ -36,6 +36,7 @@ math.h: math.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(ARG_NONNULL_H) $( -e 's/@''GNULIB_CEILL''@/$(GNULIB_CEILL)/g' \ -e 's/@''GNULIB_COSL''@/$(GNULIB_COSL)/g' \ -e 's/@''GNULIB_EXPL''@/$(GNULIB_EXPL)/g' \ + -e 's/@''GNULIB_FABSF''@/$(GNULIB_FABSF)/g' \ -e 's/@''GNULIB_FLOOR''@/$(GNULIB_FLOOR)/g' \ -e 's/@''GNULIB_FLOORF''@/$(GNULIB_FLOORF)/g' \ -e 's/@''GNULIB_FLOORL''@/$(GNULIB_FLOORL)/g' \ @@ -66,6 +67,7 @@ math.h: math.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(ARG_NONNULL_H) $( -e 's|@''HAVE_ATANL''@|$(HAVE_ATANL)|g' \ -e 's|@''HAVE_COSL''@|$(HAVE_COSL)|g' \ -e 's|@''HAVE_EXPL''@|$(HAVE_EXPL)|g' \ + -e 's|@''HAVE_FABSF''@|$(HAVE_FABSF)|g' \ -e 's|@''HAVE_ISNANF''@|$(HAVE_ISNANF)|g' \ -e 's|@''HAVE_ISNAND''@|$(HAVE_ISNAND)|g' \ -e 's|@''HAVE_ISNANL''@|$(HAVE_ISNANL)|g' \ diff --git a/tests/test-math-c++.cc b/tests/test-math-c++.cc index 2a3acff6b..183b37c4b 100644 --- a/tests/test-math-c++.cc +++ b/tests/test-math-c++.cc @@ -35,6 +35,9 @@ //SIGNATURE_CHECK (GNULIB_NAMESPACE::erf, double, (double)); //SIGNATURE_CHECK (GNULIB_NAMESPACE::erfc, double, (double)); //SIGNATURE_CHECK (GNULIB_NAMESPACE::exp, double, (double)); +#if GNULIB_TEST_FABSF +SIGNATURE_CHECK (GNULIB_NAMESPACE::fabsf, float, (float)); +#endif //SIGNATURE_CHECK (GNULIB_NAMESPACE::fabs, double, (double)); //SIGNATURE_CHECK (GNULIB_NAMESPACE::fmod, double, (double, double)); #if GNULIB_TEST_FREXP -- 2.11.0