From 83f7d47767e4c9cfdbf17f2415fe9c8028ff7da8 Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Thu, 1 Mar 2012 03:36:14 +0100 Subject: [PATCH] cbrtf: Work around bug in IRIX 6.5 system function. * lib/math.in.h (cbrtf): Override if REPLACE_CBRTF is 1. * m4/cbrtf.m4 (gl_FUNC_CBRTF_WORKS): New macro. (gl_FUNC_CBRTF): Invoke it. Set REPLACE_CBRTF to 1 if cbrtf() does not work. * m4/math_h.m4 (gl_MATH_H_DEFAULTS): Initialize REPLACE_CBRTF. * modules/math (Makefile.am): Substitute REPLACE_CBRTF. * modules/cbrtf (configure.ac): Consider REPLACE_CBRTF. (Depends-on): Update conditions. * doc/posix-functions/cbrtf.texi: Mention the IRIX 6.5 problem. --- ChangeLog | 13 +++++++++ doc/posix-functions/cbrtf.texi | 3 ++ lib/math.in.h | 13 +++++++-- m4/cbrtf.m4 | 50 +++++++++++++++++++++++++++++++++- m4/math_h.m4 | 3 +- modules/cbrtf | 10 +++---- modules/math | 3 +- 7 files changed, 85 insertions(+), 10 deletions(-) diff --git a/ChangeLog b/ChangeLog index bce2fa1e4e..6f6dbbada8 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,16 @@ +2012-02-29 Bruno Haible + + cbrtf: Work around bug in IRIX 6.5 system function. + * lib/math.in.h (cbrtf): Override if REPLACE_CBRTF is 1. + * m4/cbrtf.m4 (gl_FUNC_CBRTF_WORKS): New macro. + (gl_FUNC_CBRTF): Invoke it. Set REPLACE_CBRTF to 1 if cbrtf() does not + work. + * m4/math_h.m4 (gl_MATH_H_DEFAULTS): Initialize REPLACE_CBRTF. + * modules/math (Makefile.am): Substitute REPLACE_CBRTF. + * modules/cbrtf (configure.ac): Consider REPLACE_CBRTF. + (Depends-on): Update conditions. + * doc/posix-functions/cbrtf.texi: Mention the IRIX 6.5 problem. + 2012-02-29 Bruno Haible Tests for module 'cbrtl'. diff --git a/doc/posix-functions/cbrtf.texi b/doc/posix-functions/cbrtf.texi index 1794bb3967..77bcc269a6 100644 --- a/doc/posix-functions/cbrtf.texi +++ b/doc/posix-functions/cbrtf.texi @@ -14,6 +14,9 @@ Minix 3.1.8, AIX 5.1, Solaris 9, MSVC 9. @item This function is not declared on some platforms: IRIX 6.5. +@item +This function returns a wrong value for a minus zero on some platforms: +IRIX 6.5. @end itemize Portability problems not fixed by Gnulib: diff --git a/lib/math.in.h b/lib/math.in.h index e435c7f32e..b359df9bbc 100644 --- a/lib/math.in.h +++ b/lib/math.in.h @@ -289,10 +289,19 @@ _GL_WARN_ON_USE (atan2f, "atan2f is unportable - " #if @GNULIB_CBRTF@ -# if !@HAVE_DECL_CBRTF@ +# if @REPLACE_CBRTF@ +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# undef cbrtf +# define cbrtf rpl_cbrtf +# endif +_GL_FUNCDECL_RPL (cbrtf, float, (float x)); +_GL_CXXALIAS_RPL (cbrtf, float, (float x)); +# else +# if !@HAVE_DECL_CBRTF@ _GL_FUNCDECL_SYS (cbrtf, float, (float x)); -# endif +# endif _GL_CXXALIAS_SYS (cbrtf, float, (float x)); +# endif _GL_CXXALIASWARN (cbrtf); #elif defined GNULIB_POSIXCHECK # undef cbrtf diff --git a/m4/cbrtf.m4 b/m4/cbrtf.m4 index cf2c6b74cd..f948bd4948 100644 --- a/m4/cbrtf.m4 +++ b/m4/cbrtf.m4 @@ -1,4 +1,4 @@ -# cbrtf.m4 serial 1 +# cbrtf.m4 serial 2 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, @@ -20,9 +20,19 @@ AC_DEFUN([gl_FUNC_CBRTF], dnl Also check whether it's declared. dnl IRIX 6.5 has cbrtf() in libm but doesn't declare it in . AC_CHECK_DECL([cbrtf], , [HAVE_DECL_CBRTF=0], [[#include ]]) + save_LIBS="$LIBS" + LIBS="$LIBS $CBRTF_LIBM" + gl_FUNC_CBRTF_WORKS + LIBS="$save_LIBS" + case "$gl_cv_func_cbrtf_works" in + *yes) ;; + *) REPLACE_CBRTF=1 ;; + esac else HAVE_CBRTF=0 HAVE_DECL_CBRTF=0 + fi + if test $HAVE_CBRTF = 0 || test $REPLACE_CBRTF = 1; then dnl Find libraries needed to link lib/cbrtf.c. AC_REQUIRE([gl_FUNC_FABSF]) AC_REQUIRE([gl_FUNC_FREXPF]) @@ -46,3 +56,41 @@ AC_DEFUN([gl_FUNC_CBRTF], fi AC_SUBST([CBRTF_LIBM]) ]) + +dnl Test whether cbrtf() works. +dnl It returns wrong values on IRIX 6.5. +AC_DEFUN([gl_FUNC_CBRTF_WORKS], +[ + AC_REQUIRE([AC_PROG_CC]) + AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles + AC_CACHE_CHECK([whether cbrtf works], [gl_cv_func_cbrtf_works], + [ + AC_RUN_IFELSE( + [AC_LANG_SOURCE([[ +#include +volatile float x; +volatile float y; +int main () +{ + extern + #ifdef __cplusplus + "C" + #endif + float cbrtf (float); + /* This test fails on IRIX 6.5. */ + x = - 0.0f; + y = cbrtf (x); + if (!(y == 0.0f)) + return 1; + return 0; +} +]])], + [gl_cv_func_cbrtf_works=yes], + [gl_cv_func_cbrtf_works=no], + [case "$host_os" in + irix*) gl_cv_func_cbrtf_works="guessing no";; + *) gl_cv_func_cbrtf_works="guessing yes";; + esac + ]) + ]) +]) diff --git a/m4/math_h.m4 b/m4/math_h.m4 index d427c1a90b..f329a8aca4 100644 --- a/m4/math_h.m4 +++ b/m4/math_h.m4 @@ -1,4 +1,4 @@ -# math_h.m4 serial 77 +# math_h.m4 serial 78 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, @@ -216,6 +216,7 @@ AC_DEFUN([gl_MATH_H_DEFAULTS], HAVE_DECL_TRUNC=1; AC_SUBST([HAVE_DECL_TRUNC]) HAVE_DECL_TRUNCF=1; AC_SUBST([HAVE_DECL_TRUNCF]) HAVE_DECL_TRUNCL=1; AC_SUBST([HAVE_DECL_TRUNCL]) + REPLACE_CBRTF=0; AC_SUBST([REPLACE_CBRTF]) REPLACE_CEIL=0; AC_SUBST([REPLACE_CEIL]) REPLACE_CEILF=0; AC_SUBST([REPLACE_CEILF]) REPLACE_CEILL=0; AC_SUBST([REPLACE_CEILL]) diff --git a/modules/cbrtf b/modules/cbrtf index 8de0368bd0..06d2b7662f 100644 --- a/modules/cbrtf +++ b/modules/cbrtf @@ -9,14 +9,14 @@ m4/mathfunc.m4 Depends-on: math -isfinite [test $HAVE_CBRTF = 0] -fabsf [test $HAVE_CBRTF = 0] -frexpf [test $HAVE_CBRTF = 0] -ldexpf [test $HAVE_CBRTF = 0] +isfinite [test $HAVE_CBRTF = 0 || test $REPLACE_CBRTF = 1] +fabsf [test $HAVE_CBRTF = 0 || test $REPLACE_CBRTF = 1] +frexpf [test $HAVE_CBRTF = 0 || test $REPLACE_CBRTF = 1] +ldexpf [test $HAVE_CBRTF = 0 || test $REPLACE_CBRTF = 1] configure.ac: gl_FUNC_CBRTF -if test $HAVE_CBRTF = 0; then +if test $HAVE_CBRTF = 0 || test $REPLACE_CBRTF = 1; then AC_LIBOBJ([cbrtf]) fi gl_MATH_MODULE_INDICATOR([cbrtf]) diff --git a/modules/math b/modules/math index 36b05e482b..41505d2f80 100644 --- a/modules/math +++ b/modules/math @@ -185,7 +185,8 @@ math.h: math.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(ARG_NONNULL_H) $( -e 's|@''HAVE_DECL_TRUNCF''@|$(HAVE_DECL_TRUNCF)|g' \ -e 's|@''HAVE_DECL_TRUNCL''@|$(HAVE_DECL_TRUNCL)|g' \ | \ - sed -e 's|@''REPLACE_CEIL''@|$(REPLACE_CEIL)|g' \ + sed -e 's|@''REPLACE_CBRTF''@|$(REPLACE_CBRTF)|g' \ + -e 's|@''REPLACE_CEIL''@|$(REPLACE_CEIL)|g' \ -e 's|@''REPLACE_CEILF''@|$(REPLACE_CEILF)|g' \ -e 's|@''REPLACE_CEILL''@|$(REPLACE_CEILL)|g' \ -e 's|@''REPLACE_FABSL''@|$(REPLACE_FABSL)|g' \ -- 2.39.5