From 9be7a7f2520e9d3dd7ff625823b0ca77de1137e6 Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Fri, 7 Oct 2011 00:59:38 +0200 Subject: [PATCH] frexpf: Work around problems on IRIX and mingw. * lib/math.in.h (frexpf): Consider also REPLACE_FREXPF. * m4/math_h.m4 (gl_MATH_H_DEFAULTS): Initialize REPLACE_FREXPF. * m4/frexpf.m4 (gl_FUNC_FREXPF_WORKS): New macro. (gl_FUNC_FREXPF): Invoke it. Set REPLACE_FREXPF. * modules/frexpf (Depends-on, configure.ac): Consider REPLACE_FREXPF. * modules/math (Makefile.am): Substitute REPLACE_FREXPF. * doc/posix-functions/frexpf.texi: Mention the IRIX and mingw problems. --- ChangeLog | 11 ++++++ doc/posix-functions/frexpf.texi | 8 ++++- lib/math.in.h | 15 ++++++-- m4/frexpf.m4 | 77 +++++++++++++++++++++++++++++++++++++++-- m4/math_h.m4 | 3 +- modules/frexpf | 4 +-- modules/math | 1 + 7 files changed, 109 insertions(+), 10 deletions(-) diff --git a/ChangeLog b/ChangeLog index 1c7f8865e..bb0fb1495 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,16 @@ 2011-10-06 Bruno Haible + frexpf: Work around problems on IRIX and mingw. + * lib/math.in.h (frexpf): Consider also REPLACE_FREXPF. + * m4/math_h.m4 (gl_MATH_H_DEFAULTS): Initialize REPLACE_FREXPF. + * m4/frexpf.m4 (gl_FUNC_FREXPF_WORKS): New macro. + (gl_FUNC_FREXPF): Invoke it. Set REPLACE_FREXPF. + * modules/frexpf (Depends-on, configure.ac): Consider REPLACE_FREXPF. + * modules/math (Makefile.am): Substitute REPLACE_FREXPF. + * doc/posix-functions/frexpf.texi: Mention the IRIX and mingw problems. + +2011-10-06 Bruno Haible + fabsf: Drop assumption about library that defines fabsf. * m4/fabsf.m4 (gl_FUNC_FABSF): Use gl_MATHFUNC macro instead of AC_CHECK_FUNCS. diff --git a/doc/posix-functions/frexpf.texi b/doc/posix-functions/frexpf.texi index 2955bb7ce..0264de225 100644 --- a/doc/posix-functions/frexpf.texi +++ b/doc/posix-functions/frexpf.texi @@ -10,10 +10,16 @@ Portability problems fixed by Gnulib: @itemize @item This function is missing on some platforms: -Minix 3.1.8, AIX 5.1, HP-UX 11, IRIX 6.5, Solaris 9. +Minix 3.1.8, AIX 5.1, HP-UX 11, Solaris 9. @item This function is only defined as a macro with arguments on some platforms: MSVC 9. +@item +This function does not work on negative zero on some platforms: +mingw. +@item +This function does not work on infinite numbers on some platforms: +IRIX 6.5, mingw. @end itemize Portability problems not fixed by Gnulib: diff --git a/lib/math.in.h b/lib/math.in.h index ba4b3b07b..2e65f7066 100644 --- a/lib/math.in.h +++ b/lib/math.in.h @@ -343,11 +343,20 @@ _GL_WARN_ON_USE (fmodf, "fmodf is unportable - " If x is infinite or NaN: mantissa = x, exp unspecified. Store exp in *EXPPTR and return mantissa. */ #if @GNULIB_FREXPF@ -# if !@HAVE_FREXPF@ -# undef frexpf +# if @REPLACE_FREXPF@ +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# undef frexpf +# define frexpf rpl_frexpf +# endif +_GL_FUNCDECL_RPL (frexpf, float, (float x, int *expptr) _GL_ARG_NONNULL ((2))); +_GL_CXXALIAS_RPL (frexpf, float, (float x, int *expptr)); +# else +# if !@HAVE_FREXPF@ +# undef frexpf _GL_FUNCDECL_SYS (frexpf, float, (float x, int *expptr) _GL_ARG_NONNULL ((2))); -# endif +# endif _GL_CXXALIAS_SYS (frexpf, float, (float x, int *expptr)); +# endif _GL_CXXALIASWARN (frexpf); #elif defined GNULIB_POSIXCHECK # undef frexpf diff --git a/m4/frexpf.m4 b/m4/frexpf.m4 index 3aa648b69..d8f58cd0f 100644 --- a/m4/frexpf.m4 +++ b/m4/frexpf.m4 @@ -1,4 +1,4 @@ -# frexpf.m4 serial 2 +# frexpf.m4 serial 3 dnl Copyright (C) 2011 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, @@ -13,10 +13,81 @@ AC_DEFUN([gl_FUNC_FREXPF], dnl exists, is defined in the same library as frexp(). This is not the case dnl on NetBSD, OpenBSD. gl_MATHFUNC([frexpf], [float], [(float, int *)]) - if test $gl_cv_func_frexpf_no_libm = no \ - && test $gl_cv_func_frexpf_in_libm = no; then + if test $gl_cv_func_frexpf_no_libm = yes \ + || test $gl_cv_func_frexpf_in_libm = yes; then + save_LIBS="$LIBS" + LIBS="$LIBS $FREXPF_LIBM" + gl_FUNC_FREXPF_WORKS + LIBS="$save_LIBS" + case "$gl_cv_func_frexpf_works" in + *yes) ;; + *) REPLACE_FREXPF=1 ;; + esac + else HAVE_FREXPF=0 + fi + if test $HAVE_FREXPF = 0 || test $REPLACE_FREXPF = 1; then FREXPF_LIBM="$FREXP_LIBM" fi AC_SUBST([FREXPF_LIBM]) ]) + +dnl Test whether frexpf() works also on infinite numbers (this fails e.g. on +dnl IRIX 6.5 and mingw) and on negative zero (this fails e.g. on mingw). +AC_DEFUN([gl_FUNC_FREXPF_WORKS], +[ + AC_REQUIRE([AC_PROG_CC]) + AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles + AC_CACHE_CHECK([whether frexpf works], [gl_cv_func_frexpf_works], + [ + AC_RUN_IFELSE( + [AC_LANG_SOURCE([[ +#include +#include +#include +/* HP cc on HP-UX 10.20 has a bug with the constant expression -0.0. + ICC 10.0 has a bug when optimizing the expression -zero. + The expression -FLT_MIN * FLT_MIN does not work when cross-compiling + to PowerPC on MacOS X 10.5. */ +#if defined __hpux || defined __sgi || defined __ICC +static float +compute_minus_zero (void) +{ + return -FLT_MIN * FLT_MIN; +} +# define minus_zero compute_minus_zero () +#else +float minus_zero = -0.0f; +#endif +int main() +{ + int result = 0; + volatile float x; + float zero = 0.0f; + /* Test on infinite numbers. */ + x = 1.0f / zero; + { + int exp; + float y = frexpf (x, &exp); + if (y != x) + result |= 1; + } + /* Test on negative zero. */ + x = minus_zero; + { + int exp; + float y = frexpf (x, &exp); + if (memcmp (&y, &x, sizeof x)) + result |= 2; + } + return result; +}]])], + [gl_cv_func_frexpf_works=yes], + [gl_cv_func_frexpf_works=no], + [case "$host_os" in + irix* | mingw*) gl_cv_func_frexpf_works="guessing no";; + *) gl_cv_func_frexpf_works="guessing yes";; + esac + ]) + ]) +]) diff --git a/m4/math_h.m4 b/m4/math_h.m4 index c0c497a7b..b78b71863 100644 --- a/m4/math_h.m4 +++ b/m4/math_h.m4 @@ -1,4 +1,4 @@ -# math_h.m4 serial 29 +# math_h.m4 serial 30 dnl Copyright (C) 2007-2011 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, @@ -137,6 +137,7 @@ AC_DEFUN([gl_MATH_H_DEFAULTS], REPLACE_FLOOR=0; AC_SUBST([REPLACE_FLOOR]) REPLACE_FLOORF=0; AC_SUBST([REPLACE_FLOORF]) REPLACE_FLOORL=0; AC_SUBST([REPLACE_FLOORL]) + REPLACE_FREXPF=0; AC_SUBST([REPLACE_FREXPF]) REPLACE_FREXP=0; AC_SUBST([REPLACE_FREXP]) REPLACE_FREXPL=0; AC_SUBST([REPLACE_FREXPL]) REPLACE_HUGE_VAL=0; AC_SUBST([REPLACE_HUGE_VAL]) diff --git a/modules/frexpf b/modules/frexpf index 057b304c1..efb2db72e 100644 --- a/modules/frexpf +++ b/modules/frexpf @@ -8,11 +8,11 @@ m4/mathfunc.m4 Depends-on: math -frexp [test $HAVE_FREXPF = 0] +frexp [test $HAVE_FREXPF = 0 || test $REPLACE_FREXPF = 1] configure.ac: gl_FUNC_FREXPF -if test $HAVE_FREXPF = 0; then +if test $HAVE_FREXPF = 0 || test $REPLACE_FREXPF = 1; then AC_LIBOBJ([frexpf]) fi gl_MATH_MODULE_INDICATOR([frexpf]) diff --git a/modules/math b/modules/math index cd0eb93c8..e645cfbbf 100644 --- a/modules/math +++ b/modules/math @@ -110,6 +110,7 @@ math.h: math.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(ARG_NONNULL_H) $( -e 's|@''REPLACE_FLOOR''@|$(REPLACE_FLOOR)|g' \ -e 's|@''REPLACE_FLOORF''@|$(REPLACE_FLOORF)|g' \ -e 's|@''REPLACE_FLOORL''@|$(REPLACE_FLOORL)|g' \ + -e 's|@''REPLACE_FREXPF''@|$(REPLACE_FREXPF)|g' \ -e 's|@''REPLACE_FREXP''@|$(REPLACE_FREXP)|g' \ -e 's|@''REPLACE_FREXPL''@|$(REPLACE_FREXPL)|g' \ -e 's|@''REPLACE_HUGE_VAL''@|$(REPLACE_HUGE_VAL)|g' \ -- 2.11.0