From 6a43f7b2199b69e39f804fd7b432f86f10c66e0e Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Mon, 27 Feb 2012 13:18:57 +0100 Subject: [PATCH] fmodf-ieee: Work around test failure on OSF/1. * m4/fmodf-ieee.m4: New file. * m4/fmodf.m4 (gl_FUNC_FMODF): If gl_FUNC_FMODF_IEEE is present, test whether fmodf works with zero arguments. Replace it if not. * lib/math.in.h (fmodf): Override if REPLACE_FMODF is 1. * m4/math_h.m4 (gl_MATH_H_DEFAULTS): Initialize REPLACE_FMODF. * modules/math (Makefile.am): Substitute REPLACE_FMODF. * modules/fmodf (configure.ac): Consider REPLACE_FMODF. (Depends-on): Update dependencies. * modules/fmodf-ieee (Files): Add m4/fmodf-ieee.m4. (configure.ac): Invoke gl_FUNC_FMODF_IEEE. * doc/posix-functions/fmodf.texi: Mention the problem on OSF/1. --- ChangeLog | 13 +++++++++++ doc/posix-functions/fmodf.texi | 3 +++ lib/math.in.h | 15 +++++++++--- m4/fmodf-ieee.m4 | 15 ++++++++++++ m4/fmodf.m4 | 52 +++++++++++++++++++++++++++++++++++++++++- m4/math_h.m4 | 3 ++- modules/fmodf | 4 ++-- modules/fmodf-ieee | 2 ++ modules/math | 1 + 9 files changed, 101 insertions(+), 7 deletions(-) create mode 100644 m4/fmodf-ieee.m4 diff --git a/ChangeLog b/ChangeLog index ea481d26c..cbd22733d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,18 @@ 2012-02-27 Bruno Haible + fmodf-ieee: Work around test failure on OSF/1. + * m4/fmodf-ieee.m4: New file. + * m4/fmodf.m4 (gl_FUNC_FMODF): If gl_FUNC_FMODF_IEEE is present, test + whether fmodf works with zero arguments. Replace it if not. + * lib/math.in.h (fmodf): Override if REPLACE_FMODF is 1. + * m4/math_h.m4 (gl_MATH_H_DEFAULTS): Initialize REPLACE_FMODF. + * modules/math (Makefile.am): Substitute REPLACE_FMODF. + * modules/fmodf (configure.ac): Consider REPLACE_FMODF. + (Depends-on): Update dependencies. + * modules/fmodf-ieee (Files): Add m4/fmodf-ieee.m4. + (configure.ac): Invoke gl_FUNC_FMODF_IEEE. + * doc/posix-functions/fmodf.texi: Mention the problem on OSF/1. + fmodf-ieee: Work around test failure on MSVC 9. * modules/fmodf-ieee (Depends-on): Add fmod-ieee. * doc/posix-functions/fmodf.texi: Mention the fmodf-ieee module. diff --git a/doc/posix-functions/fmodf.texi b/doc/posix-functions/fmodf.texi index 68ff51b65..27e6638ea 100644 --- a/doc/posix-functions/fmodf.texi +++ b/doc/posix-functions/fmodf.texi @@ -19,6 +19,9 @@ MSVC 9. Portability problems fixed by Gnulib module @code{fmodf-ieee}: @itemize @item +This function has problems when the second argument is zero on some platforms: +OSF/1 5.1. +@item This function has problems when the first argument is minus zero on some platforms: MSVC 9. diff --git a/lib/math.in.h b/lib/math.in.h index abbfc6291..219104116 100644 --- a/lib/math.in.h +++ b/lib/math.in.h @@ -615,11 +615,20 @@ _GL_WARN_ON_USE (fmal, "fmal is unportable - " #if @GNULIB_FMODF@ -# if !@HAVE_FMODF@ -# undef fmodf +# if @REPLACE_FMODF@ +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# undef fmodf +# define fmodf rpl_fmodf +# endif +_GL_FUNCDECL_RPL (fmodf, float, (float x, float y)); +_GL_CXXALIAS_RPL (fmodf, float, (float x, float y)); +# else +# if !@HAVE_FMODF@ +# undef fmodf _GL_FUNCDECL_SYS (fmodf, float, (float x, float y)); -# endif +# endif _GL_CXXALIAS_SYS (fmodf, float, (float x, float y)); +# endif _GL_CXXALIASWARN (fmodf); #elif defined GNULIB_POSIXCHECK # undef fmodf diff --git a/m4/fmodf-ieee.m4 b/m4/fmodf-ieee.m4 new file mode 100644 index 000000000..883b0bec5 --- /dev/null +++ b/m4/fmodf-ieee.m4 @@ -0,0 +1,15 @@ +# fmodf-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 fmodf.m4 and not inlined in the +dnl module description), so that gl_FUNC_FMODF can test whether 'aclocal' has +dnl found uses of this macro. + +AC_DEFUN([gl_FUNC_FMODF_IEEE], +[ + m4_divert_text([INIT_PREPARE], [gl_fmodf_required=ieee]) + AC_REQUIRE([gl_FUNC_FMODF]) +]) diff --git a/m4/fmodf.m4 b/m4/fmodf.m4 index cc0e666c0..812140d6f 100644 --- a/m4/fmodf.m4 +++ b/m4/fmodf.m4 @@ -1,4 +1,4 @@ -# fmodf.m4 serial 1 +# fmodf.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,7 @@ dnl with or without modifications, as long as this notice is preserved. AC_DEFUN([gl_FUNC_FMODF], [ + m4_divert_text([DEFAULTS], [gl_fmodf_required=plain]) AC_REQUIRE([gl_MATH_H_DEFAULTS]) AC_REQUIRE([gl_FUNC_FMOD]) @@ -17,8 +18,57 @@ AC_DEFUN([gl_FUNC_FMODF], LIBS="$save_LIBS" if test $ac_cv_func_fmodf = yes; then FMODF_LIBM="$FMOD_LIBM" + m4_ifdef([gl_FUNC_FMODF_IEEE], [ + if test $gl_fmodf_required = ieee && test $REPLACE_FMODF = 0; then + AC_CACHE_CHECK([whether fmodf works according to ISO C 99 with IEC 60559], + [gl_cv_func_fmodf_ieee], + [ + save_LIBS="$LIBS" + LIBS="$LIBS $FMODF_LIBM" + AC_RUN_IFELSE( + [AC_LANG_SOURCE([[ +#ifndef __NO_MATH_INLINES +# define __NO_MATH_INLINES 1 /* for glibc */ +#endif +#include +/* 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 y) { return 0; } +int main (int argc, char *argv[]) +{ + float (*my_fmodf) (float, float) = argc ? fmodf : dummy; + float i; + float f; + /* Test fmodf(...,0.0f). + This test fails on OSF/1 5.1. */ + f = my_fmodf (2.0f, 0.0f); + if (numeric_equal (f, f)) + return 1; + return 0; +} + ]])], + [gl_cv_func_fmodf_ieee=yes], + [gl_cv_func_fmodf_ieee=no], + [gl_cv_func_fmodf_ieee="guessing no"]) + LIBS="$save_LIBS" + ]) + case "$gl_cv_func_fmodf_ieee" in + *yes) ;; + *) REPLACE_FMODF=1 ;; + esac + fi + ]) else HAVE_FMODF=0 + fi + if test $HAVE_FMODF = 0 || test $REPLACE_FMODF = 1; then + dnl Find libraries needed to link lib/fmodf.c. FMODF_LIBM="$FMOD_LIBM" fi AC_SUBST([FMODF_LIBM]) diff --git a/m4/math_h.m4 b/m4/math_h.m4 index 81c9da951..34885e0a8 100644 --- a/m4/math_h.m4 +++ b/m4/math_h.m4 @@ -1,4 +1,4 @@ -# math_h.m4 serial 67 +# math_h.m4 serial 68 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, @@ -214,6 +214,7 @@ AC_DEFUN([gl_MATH_H_DEFAULTS], REPLACE_FMAF=0; AC_SUBST([REPLACE_FMAF]) REPLACE_FMAL=0; AC_SUBST([REPLACE_FMAL]) REPLACE_FMOD=0; AC_SUBST([REPLACE_FMOD]) + REPLACE_FMODF=0; AC_SUBST([REPLACE_FMODF]) REPLACE_FMODL=0; AC_SUBST([REPLACE_FMODL]) REPLACE_FREXPF=0; AC_SUBST([REPLACE_FREXPF]) REPLACE_FREXP=0; AC_SUBST([REPLACE_FREXP]) diff --git a/modules/fmodf b/modules/fmodf index 705ce3b93..fa49437a6 100644 --- a/modules/fmodf +++ b/modules/fmodf @@ -7,11 +7,11 @@ m4/fmodf.m4 Depends-on: math -fmod [test $HAVE_FMODF = 0] +fmod [test $HAVE_FMODF = 0 || test $REPLACE_FMODF = 1] configure.ac: gl_FUNC_FMODF -if test $HAVE_FMODF = 0; then +if test $HAVE_FMODF = 0 || test $REPLACE_FMODF = 1; then AC_LIBOBJ([fmodf]) fi gl_MATH_MODULE_INDICATOR([fmodf]) diff --git a/modules/fmodf-ieee b/modules/fmodf-ieee index 9569c9173..b4e33b945 100644 --- a/modules/fmodf-ieee +++ b/modules/fmodf-ieee @@ -2,6 +2,7 @@ Description: fmodf() function according to ISO C 99 with IEC 60559. Files: +m4/fmodf-ieee.m4 Depends-on: fmodf @@ -9,6 +10,7 @@ fpieee fmod-ieee [test $HAVE_FMODF = 0] configure.ac: +gl_FUNC_FMODF_IEEE Makefile.am: diff --git a/modules/math b/modules/math index 8dd062530..612aebedd 100644 --- a/modules/math +++ b/modules/math @@ -183,6 +183,7 @@ math.h: math.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(ARG_NONNULL_H) $( -e 's|@''REPLACE_FMAF''@|$(REPLACE_FMAF)|g' \ -e 's|@''REPLACE_FMAL''@|$(REPLACE_FMAL)|g' \ -e 's|@''REPLACE_FMOD''@|$(REPLACE_FMOD)|g' \ + -e 's|@''REPLACE_FMODF''@|$(REPLACE_FMODF)|g' \ -e 's|@''REPLACE_FMODL''@|$(REPLACE_FMODL)|g' \ -e 's|@''REPLACE_FREXPF''@|$(REPLACE_FREXPF)|g' \ -e 's|@''REPLACE_FREXP''@|$(REPLACE_FREXP)|g' \ -- 2.11.0