From 49d6b5a8396bdfb66bba54d59fe8ce750911f6f1 Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Mon, 27 Feb 2012 03:13:00 +0100 Subject: [PATCH] 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. --- ChangeLog | 15 ++++++++++ doc/posix-functions/modff.texi | 14 +++++++-- lib/math.in.h | 15 ++++++++-- m4/math_h.m4 | 3 +- m4/modff-ieee.m4 | 15 ++++++++++ m4/modff.m4 | 67 ++++++++++++++++++++++++++++++++++++++++-- modules/math | 1 + modules/modff | 4 +-- modules/modff-ieee | 5 ++++ 9 files changed, 128 insertions(+), 11 deletions(-) create mode 100644 m4/modff-ieee.m4 diff --git a/ChangeLog b/ChangeLog index 548511101..3e0fc21e6 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,20 @@ 2012-02-26 Bruno Haible + 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 diff --git a/doc/posix-functions/modff.texi b/doc/posix-functions/modff.texi index d462a045b..4618b9504 100644 --- 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 @@ This function is only defined as a buggy macro with arguments on some platforms: 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 diff --git a/lib/math.in.h b/lib/math.in.h index 5fb014d1c..b5fc9164d 100644 --- a/lib/math.in.h +++ b/lib/math.in.h @@ -866,11 +866,20 @@ _GL_WARN_ON_USE (log10l, "log10l is unportable - " #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 +# endif _GL_CXXALIAS_SYS (modff, float, (float x, float *iptr)); +# endif _GL_CXXALIASWARN (modff); #elif defined GNULIB_POSIXCHECK # undef modff diff --git a/m4/math_h.m4 b/m4/math_h.m4 index 4a1980a4f..8afa4ba7d 100644 --- 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 @@ AC_DEFUN([gl_MATH_H_DEFAULTS], 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]) diff --git a/m4/modff-ieee.m4 b/m4/modff-ieee.m4 new file mode 100644 index 000000000..7e0cc10d0 --- /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]) +]) diff --git a/m4/modff.m4 b/m4/modff.m4 index 6bccc7592..993e56900 100644 --- 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 @@ dnl with or without modifications, as long as this notice is preserved. 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 @@ AC_DEFUN([gl_FUNC_MODFF], 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 +]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]) diff --git a/modules/math b/modules/math index 03f304f53..8e8ff5689 100644 --- a/modules/math +++ b/modules/math @@ -192,6 +192,7 @@ math.h: math.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(ARG_NONNULL_H) $( -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' \ diff --git a/modules/modff b/modules/modff index 15512136f..894bf67dc 100644 --- a/modules/modff +++ b/modules/modff @@ -8,11 +8,11 @@ m4/mathfunc.m4 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]) diff --git a/modules/modff-ieee b/modules/modff-ieee index eee40b9f7..d6c9b26eb 100644 --- a/modules/modff-ieee +++ b/modules/modff-ieee @@ -2,12 +2,17 @@ Description: modff() function according to ISO C 99 with IEC 60559. Files: +m4/modff-ieee.m4 +m4/minus-zero.m4 +m4/signbit.m4 Depends-on: modff fpieee +modf-ieee [test $HAVE_MODFF = 0] configure.ac: +gl_FUNC_MODFF_IEEE Makefile.am: -- 2.11.0