Mercurial > hg > octave-lyh > gnulib-hg
changeset 16408:b895d48831cd
New module 'modfl'.
* lib/math.in.h (modfl): New declaration.
* lib/modfl.c: New file.
* m4/modfl.m4: New file.
* m4/math_h.m4 (gl_MATH_H): Test whether modfl is declared.
(gl_MATH_H_DEFAULTS): Initialize GNULIB_MODFL, HAVE_MODFL.
* modules/math (Makefile.am): Substitute GNULIB_MODFL, HAVE_MODFL.
* modules/modfl: New file.
* doc/posix-functions/modfl.texi: Mention the new module.
author | Bruno Haible <bruno@clisp.org> |
---|---|
date | Sat, 25 Feb 2012 15:30:53 +0100 |
parents | dfbb60f78aef |
children | e0968c2ae37e |
files | ChangeLog doc/posix-functions/modfl.texi lib/math.in.h lib/modfl.c m4/math_h.m4 m4/modfl.m4 modules/math modules/modfl |
diffstat | 8 files changed, 143 insertions(+), 7 deletions(-) [+] |
line wrap: on
line diff
--- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,15 @@ +2012-02-25 Bruno Haible <bruno@clisp.org> + + New module 'modfl'. + * lib/math.in.h (modfl): New declaration. + * lib/modfl.c: New file. + * m4/modfl.m4: New file. + * m4/math_h.m4 (gl_MATH_H): Test whether modfl is declared. + (gl_MATH_H_DEFAULTS): Initialize GNULIB_MODFL, HAVE_MODFL. + * modules/math (Makefile.am): Substitute GNULIB_MODFL, HAVE_MODFL. + * modules/modfl: New file. + * doc/posix-functions/modfl.texi: Mention the new module. + 2012-02-25 Bruno Haible <bruno@clisp.org> Tests for module 'fabsl'.
--- a/doc/posix-functions/modfl.texi +++ b/doc/posix-functions/modfl.texi @@ -4,14 +4,10 @@ POSIX specification:@* @url{http://www.opengroup.org/onlinepubs/9699919799/functions/modfl.html} -Gnulib module: --- +Gnulib module: modfl Portability problems fixed by Gnulib: @itemize -@end itemize - -Portability problems not fixed by Gnulib: -@itemize @item This function is missing on some platforms: FreeBSD 6.0, NetBSD 5.0, OpenBSD 3.8, Minix 3.1.8, HP-UX 11, IRIX 6.5, Solaris 9, Cygwin, Interix 3.5. @@ -19,3 +15,7 @@ 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
--- a/lib/math.in.h +++ b/lib/math.in.h @@ -841,6 +841,22 @@ # endif #endif +#if @GNULIB_MODFL@ +# if !@HAVE_MODFL@ +# undef modfl +_GL_FUNCDECL_SYS (modfl, long double, (long double x, long double *iptr) + _GL_ARG_NONNULL ((2))); +# endif +_GL_CXXALIAS_SYS (modfl, long double, (long double x, long double *iptr)); +_GL_CXXALIASWARN (modfl); +#elif defined GNULIB_POSIXCHECK +# undef modfl +# if HAVE_RAW_DECL_MODFL +_GL_WARN_ON_USE (modfl, "modfl is unportable - " + "use gnulib module modfl for portability"); +# endif +#endif + #if @GNULIB_POWF@ # if !@HAVE_POWF@
new file mode 100644 --- /dev/null +++ b/lib/modfl.c @@ -0,0 +1,43 @@ +/* Get signed integer and fractional parts of a floating-point number. + Copyright (C) 2012 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 <http://www.gnu.org/licenses/>. */ + +#include <config.h> + +/* Specification. */ +#include <math.h> + +#if HAVE_SAME_LONG_DOUBLE_AS_DOUBLE + +long double +modfl (long double x, long double *iptr) +{ + double integer_part; + double fractional_part = modf (x, &integer_part); + *iptr = integer_part; + return fractional_part; +} + +#else + +long double +modfl (long double x, long double *iptr) +{ + long double integer_part = truncl (x); + *iptr = integer_part; + return x - integer_part; +} + +#endif
--- a/m4/math_h.m4 +++ b/m4/math_h.m4 @@ -1,4 +1,4 @@ -# math_h.m4 serial 57 +# math_h.m4 serial 58 dnl Copyright (C) 2007-2012 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, @@ -42,7 +42,7 @@ [acosf acosl asinf asinl atanf atanl ceilf ceill copysign copysignf copysignl cosf cosl coshf expf expl fabsf fabsl floorf floorl fma fmaf fmal fmodf frexpf frexpl - ldexpf ldexpl logb logf logl log10f modff powf + ldexpf ldexpl logb logf logl log10f modff modfl powf rint rintf rintl round roundf roundl sinf sinl sinhf sqrtf sqrtl tanf tanl tanhf trunc truncf truncl]) ]) @@ -101,6 +101,7 @@ GNULIB_LOGL=0; AC_SUBST([GNULIB_LOGL]) GNULIB_LOG10F=0; AC_SUBST([GNULIB_LOG10F]) GNULIB_MODFF=0; AC_SUBST([GNULIB_MODFF]) + GNULIB_MODFL=0; AC_SUBST([GNULIB_MODFL]) GNULIB_POWF=0; AC_SUBST([GNULIB_POWF]) GNULIB_RINT=0; AC_SUBST([GNULIB_RINT]) GNULIB_RINTF=0; AC_SUBST([GNULIB_RINTF]) @@ -151,6 +152,7 @@ HAVE_LOGL=1; AC_SUBST([HAVE_LOGL]) HAVE_LOG10F=1; AC_SUBST([HAVE_LOG10F]) HAVE_MODFF=1; AC_SUBST([HAVE_MODFF]) + HAVE_MODFL=1; AC_SUBST([HAVE_MODFL]) HAVE_POWF=1; AC_SUBST([HAVE_POWF]) HAVE_RINT=1; AC_SUBST([HAVE_RINT]) HAVE_RINTF=1; AC_SUBST([HAVE_RINTF])
new file mode 100644 --- /dev/null +++ b/m4/modfl.m4 @@ -0,0 +1,28 @@ +# modfl.m4 serial 1 +dnl Copyright (C) 2011-2012 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_MODFL], +[ + AC_REQUIRE([gl_MATH_H_DEFAULTS]) + AC_REQUIRE([gl_LONG_DOUBLE_VS_DOUBLE]) + + dnl Test whether modfl() exists. We cannot assume that modfl(), if it + dnl exists, is defined in the same library as modf(). This is not the case + dnl on FreeBSD, Solaris. + gl_MATHFUNC([modfl], [long double], [(long double, long double *)]) + if test $gl_cv_func_modfl_no_libm = no \ + && test $gl_cv_func_modfl_in_libm = no; then + HAVE_MODFL=0 + if test $HAVE_SAME_LONG_DOUBLE_AS_DOUBLE = 1; then + AC_REQUIRE([gl_FUNC_MODF]) + MODFL_LIBM="$MODF_LIBM" + else + AC_REQUIRE([gl_FUNC_TRUNCL]) + MODFL_LIBM="$TRUNCL_LIBM" + fi + fi + AC_SUBST([MODFL_LIBM]) +])
--- a/modules/math +++ b/modules/math @@ -71,6 +71,7 @@ -e 's/@''GNULIB_LOGL''@/$(GNULIB_LOGL)/g' \ -e 's/@''GNULIB_LOG10F''@/$(GNULIB_LOG10F)/g' \ -e 's/@''GNULIB_MODFF''@/$(GNULIB_MODFF)/g' \ + -e 's/@''GNULIB_MODFL''@/$(GNULIB_MODFL)/g' \ -e 's/@''GNULIB_POWF''@/$(GNULIB_POWF)/g' \ -e 's/@''GNULIB_RINT''@/$(GNULIB_RINT)/g' \ -e 's/@''GNULIB_RINTF''@/$(GNULIB_RINTF)/g' \ @@ -121,6 +122,7 @@ -e 's|@''HAVE_LOGL''@|$(HAVE_LOGL)|g' \ -e 's|@''HAVE_LOG10F''@|$(HAVE_LOG10F)|g' \ -e 's|@''HAVE_MODFF''@|$(HAVE_MODFF)|g' \ + -e 's|@''HAVE_MODFL''@|$(HAVE_MODFL)|g' \ -e 's|@''HAVE_POWF''@|$(HAVE_POWF)|g' \ -e 's|@''HAVE_RINT''@|$(HAVE_RINT)|g' \ -e 's|@''HAVE_RINTF''@|$(HAVE_RINTF)|g' \
new file mode 100644 --- /dev/null +++ b/modules/modfl @@ -0,0 +1,33 @@ +Description: +modfl() function: get signed integer and fractional parts. + +Files: +lib/modfl.c +m4/modfl.m4 +m4/mathfunc.m4 + +Depends-on: +math +modf [test $HAVE_MODFL = 0 && test $HAVE_SAME_LONG_DOUBLE_AS_DOUBLE = 1] +truncl [test $HAVE_MODFL = 0 && test $HAVE_SAME_LONG_DOUBLE_AS_DOUBLE = 0] + +configure.ac: +gl_FUNC_MODFL +if test $HAVE_MODFL = 0; then + AC_LIBOBJ([modfl]) +fi +gl_MATH_MODULE_INDICATOR([modfl]) + +Makefile.am: + +Include: +<math.h> + +Link: +$(MODFL_LIBM) + +License: +LGPL + +Maintainer: +Bruno Haible