From: Bruno Haible Date: Wed, 5 Oct 2011 23:01:52 +0000 (+0200) Subject: New module 'fmodf'. X-Git-Tag: v0.1~1694 X-Git-Url: http://erislabs.org.uk/gitweb/?a=commitdiff_plain;h=efad011252b012d39066be02454855be49170852;p=gnulib.git New module 'fmodf'. * lib/math.in.h (fmodf): New declaration. * lib/fmodf.c: New file. * m4/fmodf.m4: New file. * m4/math_h.m4 (gl_MATH_H): Test whether fmodf is declared. (gl_MATH_H_DEFAULTS): Initialize GNULIB_FMODF, HAVE_FMODF. * modules/math (Makefile.am): Substitute GNULIB_FMODF, HAVE_FMODF. * modules/fmodf: New file. * tests/test-math-c++.cc: Check the declaration of fmodf. * doc/posix-functions/fmodf.texi: Mention the new module. --- diff --git a/ChangeLog b/ChangeLog index 7500a8826..a3c8e7204 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,16 @@ 2011-10-05 Bruno Haible + New module 'fmodf'. + * lib/math.in.h (fmodf): New declaration. + * lib/fmodf.c: New file. + * m4/fmodf.m4: New file. + * m4/math_h.m4 (gl_MATH_H): Test whether fmodf is declared. + (gl_MATH_H_DEFAULTS): Initialize GNULIB_FMODF, HAVE_FMODF. + * modules/math (Makefile.am): Substitute GNULIB_FMODF, HAVE_FMODF. + * modules/fmodf: New file. + * tests/test-math-c++.cc: Check the declaration of fmodf. + * doc/posix-functions/fmodf.texi: Mention the new module. + fmod: Use a .m4 file. * m4/fmod.m4: New file. * modules/fmod (Files): Add it. diff --git a/doc/posix-functions/fmodf.texi b/doc/posix-functions/fmodf.texi index 38630295d..eb2614ea3 100644 --- a/doc/posix-functions/fmodf.texi +++ b/doc/posix-functions/fmodf.texi @@ -8,10 +8,6 @@ Gnulib module: --- 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/fmodf.c b/lib/fmodf.c new file mode 100644 index 000000000..35a8a233c --- /dev/null +++ b/lib/fmodf.c @@ -0,0 +1,26 @@ +/* Remainder. + 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 +fmodf (float x, float y) +{ + return (float) fmod ((double) x, (double) y); +} diff --git a/lib/math.in.h b/lib/math.in.h index 73ad15d50..110a1e6c8 100644 --- a/lib/math.in.h +++ b/lib/math.in.h @@ -358,6 +358,22 @@ _GL_WARN_ON_USE (floorl, "floorl is unportable - " #endif +#if @GNULIB_FMODF@ +# if !@HAVE_FMODF@ +# undef fmodf +_GL_FUNCDECL_SYS (fmodf, float, (float x, float y)); +# endif +_GL_CXXALIAS_SYS (fmodf, float, (float x, float y)); +_GL_CXXALIASWARN (fmodf); +#elif defined GNULIB_POSIXCHECK +# undef fmodf +# if HAVE_RAW_DECL_FMODF +_GL_WARN_ON_USE (fmodf, "fmodf is unportable - " + "use gnulib module fmodf for portability"); +# endif +#endif + + /* Write x as x = mantissa * 2^exp where diff --git a/m4/fmodf.m4 b/m4/fmodf.m4 new file mode 100644 index 000000000..2666d7842 --- /dev/null +++ b/m4/fmodf.m4 @@ -0,0 +1,25 @@ +# fmodf.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_FMODF], +[ + AC_REQUIRE([gl_MATH_H_DEFAULTS]) + AC_REQUIRE([gl_FUNC_FMOD]) + + dnl Test whether fmodf() exists. Assume that fmodf(), if it exists, is + dnl defined in the same library as fmod(). + save_LIBS="$LIBS" + LIBS="$LIBS $FMOD_LIBM" + AC_CHECK_FUNCS([fmodf]) + LIBS="$save_LIBS" + if test $ac_cv_func_fmodf = yes; then + FMODF_LIBM="$FMOD_LIBM" + else + HAVE_FMODF=0 + FMODF_LIBM="$FMOD_LIBM" + fi + AC_SUBST([FMODF_LIBM]) +]) diff --git a/m4/math_h.m4 b/m4/math_h.m4 index 4aee605bf..4d4b44332 100644 --- a/m4/math_h.m4 +++ b/m4/math_h.m4 @@ -1,4 +1,4 @@ -# math_h.m4 serial 26 +# math_h.m4 serial 27 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, @@ -39,7 +39,7 @@ AC_DEFUN([gl_MATH_H], dnl Check for declarations of anything we want to poison if the dnl corresponding gnulib module is not in use. gl_WARN_ON_USE_PREPARE([[#include ]], - [acosl asinl atanl ceilf ceill cosl expl fabsf floorf floorl frexpl + [acosl asinl atanl ceilf ceill cosl expl fabsf floorf floorl fmodf frexpl ldexpl logb logl round roundf roundl sinl sqrtl tanl trunc truncf truncl]) ]) @@ -66,6 +66,7 @@ AC_DEFUN([gl_MATH_H_DEFAULTS], GNULIB_FLOOR=0; AC_SUBST([GNULIB_FLOOR]) GNULIB_FLOORF=0; AC_SUBST([GNULIB_FLOORF]) GNULIB_FLOORL=0; AC_SUBST([GNULIB_FLOORL]) + GNULIB_FMODF=0; AC_SUBST([GNULIB_FMODF]) GNULIB_FREXP=0; AC_SUBST([GNULIB_FREXP]) GNULIB_FREXPL=0; AC_SUBST([GNULIB_FREXPL]) GNULIB_ISFINITE=0; AC_SUBST([GNULIB_ISFINITE]) @@ -94,6 +95,7 @@ AC_DEFUN([gl_MATH_H_DEFAULTS], HAVE_COSL=1; AC_SUBST([HAVE_COSL]) HAVE_EXPL=1; AC_SUBST([HAVE_EXPL]) HAVE_FABSF=1; AC_SUBST([HAVE_FABSF]) + HAVE_FMODF=1; AC_SUBST([HAVE_FMODF]) 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/fmodf b/modules/fmodf new file mode 100644 index 000000000..6d9276d5a --- /dev/null +++ b/modules/fmodf @@ -0,0 +1,31 @@ +Description: +fmodf() function: remainder. + +Files: +lib/fmodf.c +m4/fmodf.m4 + +Depends-on: +math +fmod [test $HAVE_FMODF = 0] + +configure.ac: +gl_FUNC_FMODF +if test $HAVE_FMODF = 0; then + AC_LIBOBJ([fmodf]) +fi +gl_MATH_MODULE_INDICATOR([fmodf]) + +Makefile.am: + +Include: + + +Link: +$(FMODF_LIBM) + +License: +LGPL + +Maintainer: +Bruno Haible diff --git a/modules/math b/modules/math index 73833ef54..68752184f 100644 --- a/modules/math +++ b/modules/math @@ -40,6 +40,7 @@ math.h: math.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(ARG_NONNULL_H) $( -e 's/@''GNULIB_FLOOR''@/$(GNULIB_FLOOR)/g' \ -e 's/@''GNULIB_FLOORF''@/$(GNULIB_FLOORF)/g' \ -e 's/@''GNULIB_FLOORL''@/$(GNULIB_FLOORL)/g' \ + -e 's/@''GNULIB_FMODF''@/$(GNULIB_FMODF)/g' \ -e 's/@''GNULIB_FREXP''@/$(GNULIB_FREXP)/g' \ -e 's/@''GNULIB_FREXPL''@/$(GNULIB_FREXPL)/g' \ -e 's/@''GNULIB_ISFINITE''@/$(GNULIB_ISFINITE)/g' \ @@ -68,6 +69,7 @@ math.h: math.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(ARG_NONNULL_H) $( -e 's|@''HAVE_COSL''@|$(HAVE_COSL)|g' \ -e 's|@''HAVE_EXPL''@|$(HAVE_EXPL)|g' \ -e 's|@''HAVE_FABSF''@|$(HAVE_FABSF)|g' \ + -e 's|@''HAVE_FMODF''@|$(HAVE_FMODF)|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 183b37c4b..b6141e12d 100644 --- a/tests/test-math-c++.cc +++ b/tests/test-math-c++.cc @@ -39,6 +39,9 @@ SIGNATURE_CHECK (GNULIB_NAMESPACE::fabsf, float, (float)); #endif //SIGNATURE_CHECK (GNULIB_NAMESPACE::fabs, double, (double)); +#if GNULIB_TEST_FMODF +SIGNATURE_CHECK (GNULIB_NAMESPACE::fmodf, float, (float, float)); +#endif //SIGNATURE_CHECK (GNULIB_NAMESPACE::fmod, double, (double, double)); #if GNULIB_TEST_FREXP SIGNATURE_CHECK (GNULIB_NAMESPACE::frexp, double, (double, int *));