Mercurial > hg > octave-lyh > gnulib-hg
changeset 16467:c5b61bdb6da4
modf-ieee: Work around test failures on *BSD, IRIX, OSF/1, Cygwin.
* m4/modf-ieee.m4: New file.
* m4/modf.m4 (gl_FUNC_MODF): If gl_FUNC_MODF_IEEE is present, test
whether modf works with NaN and Inf. Replace it if not.
* lib/math.in.h (modf): New declaration.
* lib/modf.c: New file.
* m4/math_h.m4 (gl_MATH_H): Test whether modf is declared.
(gl_MATH_H_DEFAULTS): Initialize GNULIB_MODF, REPLACE_MODF.
* modules/math (Makefile.am): Substitute GNULIB_MODF, REPLACE_MODF.
* modules/modf (Files): Add lib/modf.c.
(Depends-on): Add math, isfinite, trunc, isinf.
(configure.ac): Addrange to compile lib/modf.c if needed.
* modules/modf-ieee (Files): Add m4/modf-ieee.m4, m4/minus-zero.m4,
m4/signbit.m4.
(configure.ac): Invoke gl_FUNC_MODF_IEEE.
* tests/test-math-c++.cc: Check the declaration of modf.
* doc/posix-functions/modf.texi: Mention the modf-ieee module.
author | Bruno Haible <bruno@clisp.org> |
---|---|
date | Mon, 27 Feb 2012 01:44:57 +0100 |
parents | 6dc0328ef312 |
children | 5ad3cc13d9c3 |
files | ChangeLog doc/posix-functions/modf.texi lib/math.in.h lib/modf.c m4/math_h.m4 m4/modf-ieee.m4 m4/modf.m4 modules/math modules/modf modules/modf-ieee tests/test-math-c++.cc |
diffstat | 11 files changed, 197 insertions(+), 6 deletions(-) [+] |
line wrap: on
line diff
--- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,23 @@ 2012-02-26 Bruno Haible <bruno@clisp.org> + modf-ieee: Work around test failures on *BSD, IRIX, OSF/1, Cygwin. + * m4/modf-ieee.m4: New file. + * m4/modf.m4 (gl_FUNC_MODF): If gl_FUNC_MODF_IEEE is present, test + whether modf works with NaN and Inf. Replace it if not. + * lib/math.in.h (modf): New declaration. + * lib/modf.c: New file. + * m4/math_h.m4 (gl_MATH_H): Test whether modf is declared. + (gl_MATH_H_DEFAULTS): Initialize GNULIB_MODF, REPLACE_MODF. + * modules/math (Makefile.am): Substitute GNULIB_MODF, REPLACE_MODF. + * modules/modf (Files): Add lib/modf.c. + (Depends-on): Add math, isfinite, trunc, isinf. + (configure.ac): Addrange to compile lib/modf.c if needed. + * modules/modf-ieee (Files): Add m4/modf-ieee.m4, m4/minus-zero.m4, + m4/signbit.m4. + (configure.ac): Invoke gl_FUNC_MODF_IEEE. + * tests/test-math-c++.cc: Check the declaration of modf. + * doc/posix-functions/modf.texi: Mention the modf-ieee module. + Tests for module 'modfl-ieee'. * modules/modfl-ieee-tests: New file. * tests/test-modfl-ieee.c: New file.
--- a/doc/posix-functions/modf.texi +++ b/doc/posix-functions/modf.texi @@ -4,10 +4,20 @@ POSIX specification:@* @url{http://www.opengroup.org/onlinepubs/9699919799/functions/modf.html} -Gnulib module: modf +Gnulib module: modf or modf-ieee + +Portability problems fixed by either Gnulib module @code{modf} or @code{modf-ieee}: +@itemize +@end itemize -Portability problems fixed by Gnulib: +Portability problems fixed by Gnulib module @code{modf-ieee}: @itemize +@item +This function has problems with a NaN argument on some platforms: +NetBSD 5.1, Cygwin. +@item +This function has problems with infinite arguments on some platforms: +FreeBSD 6.4, OpenBSD 4.9, IRIX 6.5, OSF/1 5.1. @end itemize Portability problems not fixed by Gnulib:
--- a/lib/math.in.h +++ b/lib/math.in.h @@ -880,6 +880,26 @@ # endif #endif +#if @GNULIB_MODF@ +# if @REPLACE_MODF@ +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# undef modf +# define modf rpl_modf +# endif +_GL_FUNCDECL_RPL (modf, double, (double x, double *iptr) _GL_ARG_NONNULL ((2))); +_GL_CXXALIAS_RPL (modf, double, (double x, double *iptr)); +# else +_GL_CXXALIAS_SYS (modf, double, (double x, double *iptr)); +# endif +_GL_CXXALIASWARN (modf); +#elif defined GNULIB_POSIXCHECK +# undef modf +# if HAVE_RAW_DECL_MODF +_GL_WARN_ON_USE (modf, "modf has portability problems - " + "use gnulib module modf for portability"); +# endif +#endif + #if @GNULIB_MODFL@ # if !@HAVE_MODFL@ # undef modfl
new file mode 100644 --- /dev/null +++ b/lib/modf.c @@ -0,0 +1,44 @@ +/* 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> + +double +modf (double x, double *iptr) +{ + if (isfinite (x)) + { + double integer_part = trunc (x); + *iptr = integer_part; + return x - integer_part; + } + else + { + if (isinf (x)) + { + *iptr = x; + return 1.0 / x; + } + else /* isnand (x) */ + { + *iptr = x; + return x; + } + } +}
--- a/m4/math_h.m4 +++ b/m4/math_h.m4 @@ -1,4 +1,4 @@ -# math_h.m4 serial 63 +# math_h.m4 serial 64 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 fmodl frexpf frexpl - ldexpf ldexpl logb logf logl log10f log10l modff modfl powf + ldexpf ldexpl logb logf logl log10f log10l modf modff modfl powf remainder remainderf remainderl rint rintf rintl round roundf roundl sinf sinl sinhf sqrtf sqrtl tanf tanl tanhf trunc truncf truncl]) @@ -103,6 +103,7 @@ GNULIB_LOGL=0; AC_SUBST([GNULIB_LOGL]) GNULIB_LOG10F=0; AC_SUBST([GNULIB_LOG10F]) GNULIB_LOG10L=0; AC_SUBST([GNULIB_LOG10L]) + GNULIB_MODF=0; AC_SUBST([GNULIB_MODF]) GNULIB_MODFF=0; AC_SUBST([GNULIB_MODFF]) GNULIB_MODFL=0; AC_SUBST([GNULIB_MODFL]) GNULIB_POWF=0; AC_SUBST([GNULIB_POWF]) @@ -219,6 +220,7 @@ REPLACE_ISINF=0; AC_SUBST([REPLACE_ISINF]) REPLACE_ISNAN=0; AC_SUBST([REPLACE_ISNAN]) REPLACE_LDEXPL=0; AC_SUBST([REPLACE_LDEXPL]) + REPLACE_MODF=0; AC_SUBST([REPLACE_MODF]) REPLACE_NAN=0; AC_SUBST([REPLACE_NAN]) REPLACE_ROUND=0; AC_SUBST([REPLACE_ROUND]) REPLACE_ROUNDF=0; AC_SUBST([REPLACE_ROUNDF])
new file mode 100644 --- /dev/null +++ b/m4/modf-ieee.m4 @@ -0,0 +1,15 @@ +# modf-ieee.m4 serial 1 +dnl Copyright (C) 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. + +dnl This macro is in a separate file (not in modf.m4 and not inlined in the +dnl module description), so that gl_FUNC_MODF can test whether 'aclocal' has +dnl found uses of this macro. + +AC_DEFUN([gl_FUNC_MODF_IEEE], +[ + m4_divert_text([INIT_PREPARE], [gl_modf_required=ieee]) + AC_REQUIRE([gl_FUNC_MODF]) +])
--- a/m4/modf.m4 +++ b/m4/modf.m4 @@ -1,4 +1,4 @@ -# modf.m4 serial 1 +# modf.m4 serial 2 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, @@ -6,6 +6,71 @@ AC_DEFUN([gl_FUNC_MODF], [ + m4_divert_text([DEFAULTS], [gl_modf_required=plain]) + AC_REQUIRE([gl_MATH_H_DEFAULTS]) + dnl Determine MODF_LIBM. gl_MATHFUNC([modf], [double], [(double, double *)]) + + m4_ifdef([gl_FUNC_MODF_IEEE], [ + if test $gl_modf_required = ieee && test $REPLACE_MODF = 0; then + AC_CACHE_CHECK([whether modf works according to ISO C 99 with IEC 60559], + [gl_cv_func_modf_ieee], + [ + save_LIBS="$LIBS" + LIBS="$LIBS $MODF_LIBM" + AC_RUN_IFELSE( + [AC_LANG_SOURCE([[ +#ifndef __NO_MATH_INLINES +# define __NO_MATH_INLINES 1 /* for glibc */ +#endif +#include <math.h> +]gl_DOUBLE_MINUS_ZERO_CODE[ +]gl_DOUBLE_SIGNBIT_CODE[ +/* Compare two numbers with ==. + This is a separate function because IRIX 6.5 "cc -O" miscompiles an + 'x == x' test. */ +static int +numeric_equal (double x, double y) +{ + return x == y; +} +static double dummy (double x, double *iptr) { return 0; } +double zero; +double minus_one = - 1.0; +int main (int argc, char *argv[]) +{ + double (*my_modf) (double, double *) = argc ? modf : dummy; + int result = 0; + double i; + double f; + /* Test modf(NaN,...). + This test fails on NetBSD 5.1, Cygwin. */ + f = my_modf (zero / zero, &i); + if (numeric_equal (f, f)) + result |= 1; + /* Test modf(-Inf,...). + This test fails on FreeBSD 6.4, OpenBSD 4.9, IRIX 6.5, OSF/1 5.1. */ + f = my_modf (minus_one / zero, &i); + if (!(f == 0.0) || (signbitd (minus_zerod) && !signbitd (f))) + result |= 2; + return result; +} + ]])], + [gl_cv_func_modf_ieee=yes], + [gl_cv_func_modf_ieee=no], + [gl_cv_func_modf_ieee="guessing no"]) + LIBS="$save_LIBS" + ]) + case "$gl_cv_func_modf_ieee" in + *yes) ;; + *) REPLACE_MODF=1 ;; + esac + fi + ]) + if test $REPLACE_MODF = 1; then + dnl Find libraries needed to link lib/modf.c. + AC_REQUIRE([gl_FUNC_TRUNC]) + MODF_LIBM="$TRUNC_LIBM" + fi ])
--- a/modules/math +++ b/modules/math @@ -72,6 +72,7 @@ -e 's/@''GNULIB_LOGL''@/$(GNULIB_LOGL)/g' \ -e 's/@''GNULIB_LOG10F''@/$(GNULIB_LOG10F)/g' \ -e 's/@''GNULIB_LOG10L''@/$(GNULIB_LOG10L)/g' \ + -e 's/@''GNULIB_MODF''@/$(GNULIB_MODF)/g' \ -e 's/@''GNULIB_MODFF''@/$(GNULIB_MODFF)/g' \ -e 's/@''GNULIB_MODFL''@/$(GNULIB_MODFL)/g' \ -e 's/@''GNULIB_POWF''@/$(GNULIB_POWF)/g' \ @@ -190,6 +191,7 @@ -e 's|@''REPLACE_ISNAN''@|$(REPLACE_ISNAN)|g' \ -e 's|@''REPLACE_ITOLD''@|$(REPLACE_ITOLD)|g' \ -e 's|@''REPLACE_LDEXPL''@|$(REPLACE_LDEXPL)|g' \ + -e 's|@''REPLACE_MODF''@|$(REPLACE_MODF)|g' \ -e 's|@''REPLACE_NAN''@|$(REPLACE_NAN)|g' \ -e 's|@''REPLACE_ROUND''@|$(REPLACE_ROUND)|g' \ -e 's|@''REPLACE_ROUNDF''@|$(REPLACE_ROUNDF)|g' \
--- a/modules/modf +++ b/modules/modf @@ -2,13 +2,22 @@ modf() function: get signed integer and fractional parts. Files: +lib/modf.c m4/modf.m4 m4/mathfunc.m4 Depends-on: +math +isfinite [test $REPLACE_MODF = 1] +trunc [test $REPLACE_MODF = 1] +isinf [test $REPLACE_MODF = 1] configure.ac: gl_FUNC_MODF +if test $REPLACE_MODF = 1; then + AC_LIBOBJ([modf]) +fi +gl_MATH_MODULE_INDICATOR([modf]) Makefile.am:
--- a/modules/modf-ieee +++ b/modules/modf-ieee @@ -2,12 +2,16 @@ modf() function according to ISO C 99 with IEC 60559. Files: +m4/modf-ieee.m4 +m4/minus-zero.m4 +m4/signbit.m4 Depends-on: modf fpieee configure.ac: +gl_FUNC_MODF_IEEE Makefile.am:
--- a/tests/test-math-c++.cc +++ b/tests/test-math-c++.cc @@ -195,7 +195,9 @@ #if GNULIB_TEST_MODFF SIGNATURE_CHECK (GNULIB_NAMESPACE::modff, float, (float, float *)); #endif -//SIGNATURE_CHECK (GNULIB_NAMESPACE::modf, double, (double, double *)); +#if GNULIB_TEST_MODF +SIGNATURE_CHECK (GNULIB_NAMESPACE::modf, double, (double, double *)); +#endif #if GNULIB_TEST_MODFL SIGNATURE_CHECK (GNULIB_NAMESPACE::modfl, long double, (long double, long double *));