Mercurial > hg > octave-lyh > gnulib-hg
changeset 16468:5ad3cc13d9c3
modff-ieee: Work around test failures on *BSD, IRIX, OSF/1, etc.
* m4/modff-ieee.m4: New file.
* m4/modff.m4 (gl_FUNC_MODFF): If gl_FUNC_MODFF_IEEE is present, test
whether modff works with NaN and Inf. Replace it if not.
* lib/math.in.h (modff): Override if REPLACE_MODFF is 1.
* m4/math_h.m4 (gl_MATH_H_DEFAULTS): Initialize REPLACE_MODFF.
* modules/math (Makefile.am): Substitute REPLACE_MODFF.
* modules/modff (configure.ac): Consider REPLACE_MODFF.
(Depends-on): Update dependencies.
* modules/modff-ieee (Files): Add m4/modff-ieee.m4, m4/minus-zero.m4,
m4/signbit.m4.
(Depends-on): Add modf-ieee.
(configure.ac): Invoke gl_FUNC_MODFF_IEEE.
* doc/posix-functions/modff.texi: Mention the modff-ieee module.
author | Bruno Haible <bruno@clisp.org> |
---|---|
date | Mon, 27 Feb 2012 03:13:00 +0100 |
parents | c5b61bdb6da4 |
children | d2bb16b4df01 |
files | ChangeLog doc/posix-functions/modff.texi lib/math.in.h m4/math_h.m4 m4/modff-ieee.m4 m4/modff.m4 modules/math modules/modff modules/modff-ieee |
diffstat | 9 files changed, 128 insertions(+), 11 deletions(-) [+] |
line wrap: on
line diff
--- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,20 @@ 2012-02-26 Bruno Haible <bruno@clisp.org> + modff-ieee: Work around test failures on *BSD, IRIX, OSF/1, etc. + * m4/modff-ieee.m4: New file. + * m4/modff.m4 (gl_FUNC_MODFF): If gl_FUNC_MODFF_IEEE is present, test + whether modff works with NaN and Inf. Replace it if not. + * lib/math.in.h (modff): Override if REPLACE_MODFF is 1. + * m4/math_h.m4 (gl_MATH_H_DEFAULTS): Initialize REPLACE_MODFF. + * modules/math (Makefile.am): Substitute REPLACE_MODFF. + * modules/modff (configure.ac): Consider REPLACE_MODFF. + (Depends-on): Update dependencies. + * modules/modff-ieee (Files): Add m4/modff-ieee.m4, m4/minus-zero.m4, + m4/signbit.m4. + (Depends-on): Add modf-ieee. + (configure.ac): Invoke gl_FUNC_MODFF_IEEE. + * doc/posix-functions/modff.texi: Mention the modff-ieee module. + 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
--- a/doc/posix-functions/modff.texi +++ b/doc/posix-functions/modff.texi @@ -4,9 +4,9 @@ POSIX specification:@* @url{http://www.opengroup.org/onlinepubs/9699919799/functions/modff.html} -Gnulib module: modff +Gnulib module: modff or modff-ieee -Portability problems fixed by Gnulib: +Portability problems fixed by either Gnulib module @code{modff} or @code{modff-ieee}: @itemize @item This function is missing on some platforms: @@ -16,6 +16,16 @@ MSVC 9. @end itemize +Portability problems fixed by Gnulib module @code{modff-ieee}: +@itemize +@item +This function has problems with a NaN argument on some platforms: +NetBSD 5.1, OpenBSD 4.9, Solaris 9, Cygwin. +@item +This function has problems with infinite arguments on some platforms: +IRIX 6.5, OSF/1 5.1, mingw. +@end itemize + Portability problems not fixed by Gnulib: @itemize @end itemize
--- a/lib/math.in.h +++ b/lib/math.in.h @@ -866,11 +866,20 @@ #if @GNULIB_MODFF@ -# if !@HAVE_MODFF@ -# undef modff +# if @REPLACE_MODFF@ +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# undef modff +# define modff rpl_modff +# endif +_GL_FUNCDECL_RPL (modff, float, (float x, float *iptr) _GL_ARG_NONNULL ((2))); +_GL_CXXALIAS_RPL (modff, float, (float x, float *iptr)); +# else +# 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)); # endif -_GL_CXXALIAS_SYS (modff, float, (float x, float *iptr)); _GL_CXXALIASWARN (modff); #elif defined GNULIB_POSIXCHECK # undef modff
--- a/m4/math_h.m4 +++ b/m4/math_h.m4 @@ -1,4 +1,4 @@ -# math_h.m4 serial 64 +# math_h.m4 serial 65 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, @@ -221,6 +221,7 @@ REPLACE_ISNAN=0; AC_SUBST([REPLACE_ISNAN]) REPLACE_LDEXPL=0; AC_SUBST([REPLACE_LDEXPL]) REPLACE_MODF=0; AC_SUBST([REPLACE_MODF]) + REPLACE_MODFF=0; AC_SUBST([REPLACE_MODFF]) 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/modff-ieee.m4 @@ -0,0 +1,15 @@ +# modff-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 modff.m4 and not inlined in the +dnl module description), so that gl_FUNC_MODFF can test whether 'aclocal' has +dnl found uses of this macro. + +AC_DEFUN([gl_FUNC_MODFF_IEEE], +[ + m4_divert_text([INIT_PREPARE], [gl_modff_required=ieee]) + AC_REQUIRE([gl_FUNC_MODFF]) +])
--- a/m4/modff.m4 +++ b/m4/modff.m4 @@ -1,4 +1,4 @@ -# modff.m4 serial 2 +# modff.m4 serial 3 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,7 @@ AC_DEFUN([gl_FUNC_MODFF], [ + m4_divert_text([DEFAULTS], [gl_modff_required=plain]) AC_REQUIRE([gl_MATH_H_DEFAULTS]) AC_REQUIRE([gl_FUNC_MODF]) @@ -13,9 +14,69 @@ dnl exists, is defined in the same library as modf(). This is not the case dnl on FreeBSD, NetBSD, OpenBSD. gl_MATHFUNC([modff], [float], [(float, float *)]) - if test $gl_cv_func_modff_no_libm = no \ - && test $gl_cv_func_modff_in_libm = no; then + if test $gl_cv_func_modff_no_libm = yes \ + || test $gl_cv_func_modff_in_libm = yes; then + m4_ifdef([gl_FUNC_MODFF_IEEE], [ + if test $gl_modff_required = ieee && test $REPLACE_MODFF = 0; then + AC_CACHE_CHECK([whether modff works according to ISO C 99 with IEC 60559], + [gl_cv_func_modff_ieee], + [ + save_LIBS="$LIBS" + LIBS="$LIBS $MODFF_LIBM" + AC_RUN_IFELSE( + [AC_LANG_SOURCE([[ +#ifndef __NO_MATH_INLINES +# define __NO_MATH_INLINES 1 /* for glibc */ +#endif +#include <math.h> +]gl_FLOAT_MINUS_ZERO_CODE[ +]gl_FLOAT_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 (float x, float y) +{ + return x == y; +} +static float dummy (float x, float *iptr) { return 0; } +float zero; +float minus_one = - 1.0f; +int main (int argc, char *argv[]) +{ + float (*my_modff) (float, float *) = argc ? modff : dummy; + int result = 0; + float i; + float f; + /* Test modff(NaN,...). + This test fails on NetBSD 5.1, OpenBSD 4.9, Solaris 9, Cygwin. */ + f = my_modff (zero / zero, &i); + if (numeric_equal (f, f)) + result |= 1; + /* Test modff(-Inf,...). + This test fails on IRIX 6.5, OSF/1 5.1, mingw. */ + f = my_modff (minus_one / zero, &i); + if (!(f == 0.0f) || (signbitf (minus_zerof) && !signbitf (f))) + result |= 2; + return result; +} + ]])], + [gl_cv_func_modff_ieee=yes], + [gl_cv_func_modff_ieee=no], + [gl_cv_func_modff_ieee="guessing no"]) + LIBS="$save_LIBS" + ]) + case "$gl_cv_func_modff_ieee" in + *yes) ;; + *) REPLACE_MODFF=1 ;; + esac + fi + ]) + else HAVE_MODFF=0 + fi + if test $HAVE_MODFF = 0 || test $REPLACE_MODFF = 1; then + dnl Find libraries needed to link lib/modff.c. MODFF_LIBM="$MODF_LIBM" fi AC_SUBST([MODFF_LIBM])
--- a/modules/math +++ b/modules/math @@ -192,6 +192,7 @@ -e 's|@''REPLACE_ITOLD''@|$(REPLACE_ITOLD)|g' \ -e 's|@''REPLACE_LDEXPL''@|$(REPLACE_LDEXPL)|g' \ -e 's|@''REPLACE_MODF''@|$(REPLACE_MODF)|g' \ + -e 's|@''REPLACE_MODFF''@|$(REPLACE_MODFF)|g' \ -e 's|@''REPLACE_NAN''@|$(REPLACE_NAN)|g' \ -e 's|@''REPLACE_ROUND''@|$(REPLACE_ROUND)|g' \ -e 's|@''REPLACE_ROUNDF''@|$(REPLACE_ROUNDF)|g' \
--- a/modules/modff +++ b/modules/modff @@ -8,11 +8,11 @@ Depends-on: math -modf [test $HAVE_MODFF = 0] +modf [test $HAVE_MODFF = 0 || test $REPLACE_MODFF = 1] configure.ac: gl_FUNC_MODFF -if test $HAVE_MODFF = 0; then +if test $HAVE_MODFF = 0 || test $REPLACE_MODFF = 1; then AC_LIBOBJ([modff]) fi gl_MATH_MODULE_INDICATOR([modff])