# HG changeset patch # User Bruno Haible # Date 1317862154 -7200 # Node ID 0e07b354626af47105efd29627a9d7d5a88a1062 # Parent dd898709f07702123e44d5e751667467a1da3767 New module 'modff'. * lib/math.in.h (modff): New declaration. * lib/modff.c: New file. * m4/modff.m4: New file. * m4/math_h.m4 (gl_MATH_H): Test whether modff is declared. (gl_MATH_H_DEFAULTS): Initialize GNULIB_MODFF, HAVE_MODFF. * modules/math (Makefile.am): Substitute GNULIB_MODFF, HAVE_MODFF. * modules/modff: New file. * tests/test-math-c++.cc: Check the declaration of modff. * doc/posix-functions/modff.texi: Mention the new module. diff --git a/ChangeLog b/ChangeLog --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,16 @@ 2011-10-05 Bruno Haible + New module 'modff'. + * lib/math.in.h (modff): New declaration. + * lib/modff.c: New file. + * m4/modff.m4: New file. + * m4/math_h.m4 (gl_MATH_H): Test whether modff is declared. + (gl_MATH_H_DEFAULTS): Initialize GNULIB_MODFF, HAVE_MODFF. + * modules/math (Makefile.am): Substitute GNULIB_MODFF, HAVE_MODFF. + * modules/modff: New file. + * tests/test-math-c++.cc: Check the declaration of modff. + * doc/posix-functions/modff.texi: Mention the new module. + modf tests: Make test sharper. * tests/test-modf.c (main): Strengthen upper bound. diff --git a/doc/posix-functions/modff.texi b/doc/posix-functions/modff.texi --- a/doc/posix-functions/modff.texi +++ b/doc/posix-functions/modff.texi @@ -4,18 +4,18 @@ POSIX specification:@* @url{http://www.opengroup.org/onlinepubs/9699919799/functions/modff.html} -Gnulib module: --- +Gnulib module: modff Portability problems fixed by Gnulib: @itemize -@end itemize - -Portability problems not fixed by Gnulib: -@itemize @item This function is missing on some platforms: MacOS X 10.5, Minix 3.1.8, AIX 5.1, HP-UX 11. @item -This function is only defined as a macro with arguments on some platforms: +This function is only defined as a buggy 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 --- a/lib/math.in.h +++ b/lib/math.in.h @@ -453,6 +453,22 @@ #endif +#if @GNULIB_MODFF@ +# if !@HAVE_MODFF@ +# undef modff +_GL_FUNCDECL_SYS (modff, float, (float x, float *iptr) _GL_ARG_NONNULL ((2))); +# endif +_GL_CXXALIAS_SYS (modff, float, (float x, float *iptr)); +_GL_CXXALIASWARN (modff); +#elif defined GNULIB_POSIXCHECK +# undef modff +# if HAVE_RAW_DECL_MODFF +_GL_WARN_ON_USE (modff, "modff is unportable - " + "use gnulib module modff for portability"); +# endif +#endif + + #if @GNULIB_ROUNDF@ # if @REPLACE_ROUNDF@ # if !(defined __cplusplus && defined GNULIB_NAMESPACE) diff --git a/lib/modff.c b/lib/modff.c new file mode 100644 --- /dev/null +++ b/lib/modff.c @@ -0,0 +1,29 @@ +/* Get signed integer and fractional parts of a floating-point number. + 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 +modff (float x, float *iptr) +{ + double i; + double frac = modf ((double) x, &i); + *iptr = (float) i; + return (float) frac; +} 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 27 +# math_h.m4 serial 28 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, @@ -40,7 +40,8 @@ dnl corresponding gnulib module is not in use. gl_WARN_ON_USE_PREPARE([[#include ]], [acosl asinl atanl ceilf ceill cosl expl fabsf floorf floorl fmodf frexpl - ldexpl logb logl round roundf roundl sinl sqrtl tanl trunc truncf truncl]) + ldexpl logb logl modff round roundf roundl sinl sqrtl + tanl trunc truncf truncl]) ]) AC_DEFUN([gl_MATH_MODULE_INDICATOR], @@ -78,6 +79,7 @@ GNULIB_LDEXPL=0; AC_SUBST([GNULIB_LDEXPL]) GNULIB_LOGB=0; AC_SUBST([GNULIB_LOGB]) GNULIB_LOGL=0; AC_SUBST([GNULIB_LOGL]) + GNULIB_MODFF=0; AC_SUBST([GNULIB_MODFF]) GNULIB_ROUND=0; AC_SUBST([GNULIB_ROUND]) GNULIB_ROUNDF=0; AC_SUBST([GNULIB_ROUNDF]) GNULIB_ROUNDL=0; AC_SUBST([GNULIB_ROUNDL]) @@ -100,6 +102,7 @@ HAVE_ISNAND=1; AC_SUBST([HAVE_ISNAND]) HAVE_ISNANL=1; AC_SUBST([HAVE_ISNANL]) HAVE_LOGL=1; AC_SUBST([HAVE_LOGL]) + HAVE_MODFF=1; AC_SUBST([HAVE_MODFF]) HAVE_SINL=1; AC_SUBST([HAVE_SINL]) HAVE_SQRTL=1; AC_SUBST([HAVE_SQRTL]) HAVE_TANL=1; AC_SUBST([HAVE_TANL]) diff --git a/m4/modff.m4 b/m4/modff.m4 new file mode 100644 --- /dev/null +++ b/m4/modff.m4 @@ -0,0 +1,25 @@ +# modff.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_MODFF], +[ + AC_REQUIRE([gl_MATH_H_DEFAULTS]) + AC_REQUIRE([gl_FUNC_MODF]) + + dnl Test whether modff() exists. Assume that modff(), if it exists, is + dnl defined in the same library as modf(). + save_LIBS="$LIBS" + LIBS="$LIBS $MODF_LIBM" + AC_CHECK_FUNCS([modff]) + LIBS="$save_LIBS" + if test $ac_cv_func_modff = yes; then + MODFF_LIBM="$MODF_LIBM" + else + HAVE_MODFF=0 + MODFF_LIBM="$MODF_LIBM" + fi + AC_SUBST([MODFF_LIBM]) +]) diff --git a/modules/math b/modules/math --- a/modules/math +++ b/modules/math @@ -52,6 +52,7 @@ -e 's/@''GNULIB_LDEXPL''@/$(GNULIB_LDEXPL)/g' \ -e 's/@''GNULIB_LOGB''@/$(GNULIB_LOGB)/g' \ -e 's/@''GNULIB_LOGL''@/$(GNULIB_LOGL)/g' \ + -e 's/@''GNULIB_MODFF''@/$(GNULIB_MODFF)/g' \ -e 's/@''GNULIB_ROUND''@/$(GNULIB_ROUND)/g' \ -e 's/@''GNULIB_ROUNDF''@/$(GNULIB_ROUNDF)/g' \ -e 's/@''GNULIB_ROUNDL''@/$(GNULIB_ROUNDL)/g' \ @@ -74,6 +75,7 @@ -e 's|@''HAVE_ISNAND''@|$(HAVE_ISNAND)|g' \ -e 's|@''HAVE_ISNANL''@|$(HAVE_ISNANL)|g' \ -e 's|@''HAVE_LOGL''@|$(HAVE_LOGL)|g' \ + -e 's|@''HAVE_MODFF''@|$(HAVE_MODFF)|g' \ -e 's|@''HAVE_SINL''@|$(HAVE_SINL)|g' \ -e 's|@''HAVE_SQRTL''@|$(HAVE_SQRTL)|g' \ -e 's|@''HAVE_TANL''@|$(HAVE_TANL)|g' \ diff --git a/modules/modff b/modules/modff new file mode 100644 --- /dev/null +++ b/modules/modff @@ -0,0 +1,31 @@ +Description: +modff() function: get signed integer and fractional parts. + +Files: +lib/modff.c +m4/modff.m4 + +Depends-on: +math +modf [test $HAVE_MODFF = 0] + +configure.ac: +gl_FUNC_MODFF +if test $HAVE_MODFF = 0; then + AC_LIBOBJ([modff]) +fi +gl_MATH_MODULE_INDICATOR([modff]) + +Makefile.am: + +Include: + + +Link: +$(MODFF_LIBM) + +License: +LGPL + +Maintainer: +Bruno Haible 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 @@ -56,6 +56,9 @@ //SIGNATURE_CHECK (GNULIB_NAMESPACE::log1p, double, (double)); //SIGNATURE_CHECK (GNULIB_NAMESPACE::logb, double, (double)); //SIGNATURE_CHECK (GNULIB_NAMESPACE::log, double, (double)); +#if GNULIB_TEST_MODFF +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)); //SIGNATURE_CHECK (GNULIB_NAMESPACE::pow, double, (double, double));