Mercurial > hg > octave-lyh > gnulib-hg
changeset 16532:1fcd2cd248a9
hypotl-ieee: Work around test failure on OSF/1 and native Windows.
* m4/hypotl-ieee.m4: New file.
* m4/hypotl.m4 (gl_FUNC_HYPOTL): If gl_FUNC_HYPOTL_IEEE is present,
test whether hypotl works with mixed NaN and Infinity arguments.
Replace it if not.
* lib/math.in.h (hypotl): Override if REPLACE_HYPOTL is 1.
* m4/math_h.m4 (gl_MATH_H_DEFAULTS): Initialize REPLACE_HYPOTL.
* modules/math (Makefile.am): Substitute REPLACE_HYPOTL.
* modules/hypotl (configure.ac): Consider REPLACE_HYPOTL.
(Depends-on): Update conditions.
* modules/hypotl-ieee (Files): Add m4/hypotl-ieee.m4.
(Depends-on): Add hypot-ieee.
(configure.ac): Invoke gl_FUNC_HYPOTL_IEEE.
* doc/posix-functions/hypotl.texi: Mention the hypotl-ieee module.
author | Bruno Haible <bruno@clisp.org> |
---|---|
date | Wed, 29 Feb 2012 20:50:49 +0100 |
parents | 89e5e3b8457d |
children | d91850ca525f |
files | ChangeLog doc/posix-functions/hypotl.texi lib/math.in.h m4/hypotl-ieee.m4 m4/hypotl.m4 m4/math_h.m4 modules/hypotl modules/hypotl-ieee modules/math |
diffstat | 9 files changed, 116 insertions(+), 14 deletions(-) [+] |
line wrap: on
line diff
--- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,20 @@ 2012-02-29 Bruno Haible <bruno@clisp.org> + hypotl-ieee: Work around test failure on OSF/1 and native Windows. + * m4/hypotl-ieee.m4: New file. + * m4/hypotl.m4 (gl_FUNC_HYPOTL): If gl_FUNC_HYPOTL_IEEE is present, + test whether hypotl works with mixed NaN and Infinity arguments. + Replace it if not. + * lib/math.in.h (hypotl): Override if REPLACE_HYPOTL is 1. + * m4/math_h.m4 (gl_MATH_H_DEFAULTS): Initialize REPLACE_HYPOTL. + * modules/math (Makefile.am): Substitute REPLACE_HYPOTL. + * modules/hypotl (configure.ac): Consider REPLACE_HYPOTL. + (Depends-on): Update conditions. + * modules/hypotl-ieee (Files): Add m4/hypotl-ieee.m4. + (Depends-on): Add hypot-ieee. + (configure.ac): Invoke gl_FUNC_HYPOTL_IEEE. + * doc/posix-functions/hypotl.texi: Mention the hypotl-ieee module. + hypotf-ieee: Work around test failure on OSF/1 and native Windows. * m4/hypotf-ieee.m4: New file. * m4/hypotf.m4 (gl_FUNC_HYPOTF): If gl_FUNC_HYPOTF_IEEE is present,
--- a/doc/posix-functions/hypotl.texi +++ b/doc/posix-functions/hypotl.texi @@ -4,15 +4,23 @@ POSIX specification:@* @url{http://www.opengroup.org/onlinepubs/9699919799/functions/hypotl.html} -Gnulib module: hypotl +Gnulib module: hypotl or hypotl-ieee -Portability problems fixed by Gnulib: +Portability problems fixed by either Gnulib module @code{hypotl} or @code{hypotl-ieee}: @itemize @item This function is missing on some platforms: FreeBSD 6.0, NetBSD 5.0, OpenBSD 3.8, Minix 3.1.8, AIX 5.1, HP-UX 11, IRIX 6.5, Solaris 9, Cygwin, MSVC 9, Interix 3.5, BeOS. @end itemize +Portability problems fixed by Gnulib module @code{hypotl-ieee}: +@itemize +@item +When the arguments are mixed NaN and Infinity, this function returns a wrong +value on some platforms: +OSF/1 5.1, mingw, MSVC 9. +@end itemize + Portability problems not fixed by Gnulib: @itemize @end itemize
--- a/lib/math.in.h +++ b/lib/math.in.h @@ -855,10 +855,19 @@ /* Return sqrt(x^2+y^2). */ #if @GNULIB_HYPOTL@ -# if !@HAVE_HYPOTL@ +# if @REPLACE_HYPOTL@ +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# undef hypotl +# define hypotl rpl_hypotl +# endif +_GL_FUNCDECL_RPL (hypotl, long double, (long double x, long double y)); +_GL_CXXALIAS_RPL (hypotl, long double, (long double x, long double y)); +# else +# if !@HAVE_HYPOTL@ _GL_FUNCDECL_SYS (hypotl, long double, (long double x, long double y)); +# endif +_GL_CXXALIAS_SYS (hypotl, long double, (long double x, long double y)); # endif -_GL_CXXALIAS_SYS (hypotl, long double, (long double x, long double y)); _GL_CXXALIASWARN (hypotl); #elif defined GNULIB_POSIXCHECK # undef hypotl
new file mode 100644 --- /dev/null +++ b/m4/hypotl-ieee.m4 @@ -0,0 +1,15 @@ +# hypotl-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 hypotl.m4 and not inlined in the +dnl module description), so that gl_FUNC_HYPOTL can test whether 'aclocal' has +dnl found uses of this macro. + +AC_DEFUN([gl_FUNC_HYPOTL_IEEE], +[ + m4_divert_text([INIT_PREPARE], [gl_hypotl_required=ieee]) + AC_REQUIRE([gl_FUNC_HYPOTL]) +])
--- a/m4/hypotl.m4 +++ b/m4/hypotl.m4 @@ -1,4 +1,4 @@ -# hypotl.m4 serial 1 +# hypotl.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, @@ -6,6 +6,7 @@ AC_DEFUN([gl_FUNC_HYPOTL], [ + m4_divert_text([DEFAULTS], [gl_hypotl_required=plain]) AC_REQUIRE([gl_MATH_H_DEFAULTS]) AC_REQUIRE([gl_FUNC_HYPOT]) @@ -17,8 +18,57 @@ LIBS="$save_LIBS" if test $ac_cv_func_hypotl = yes; then HYPOTL_LIBM="$HYPOT_LIBM" + m4_ifdef([gl_FUNC_HYPOTL_IEEE], [ + if test $gl_hypotl_required = ieee && test $REPLACE_HYPOTL = 0; then + AC_CACHE_CHECK([whether hypotl works according to ISO C 99 with IEC 60559], + [gl_cv_func_hypotl_ieee], + [ + save_LIBS="$LIBS" + LIBS="$LIBS $HYPOTL_LIBM" + AC_RUN_IFELSE( + [AC_LANG_SOURCE([[ +#ifndef __NO_MATH_INLINES +# define __NO_MATH_INLINES 1 /* for glibc */ +#endif +#include <math.h> +/* Compare two numbers with ==. + This is a separate function because IRIX 6.5 "cc -O" miscompiles an + 'x == x' test. */ +static int +numeric_equal (long double x, long double y) +{ + return x == y; +} +static long double dummy (long double x, long double y) { return 0; } +long double zero; +long double one = 1.0L; +int main (int argc, char *argv[]) +{ + long double (*my_hypotl) (long double, long double) = argc ? hypotl : dummy; + long double f; + /* Test hypotl(NaN,Infinity). + This test fails on OSF/1 5.1 and native Windows. */ + f = my_hypotl (zero / zero, one / zero); + if (!numeric_equal (f, f)) + return 1; + return 0; +} + ]])], + [gl_cv_func_hypotl_ieee=yes], + [gl_cv_func_hypotl_ieee=no], + [gl_cv_func_hypotl_ieee="guessing no"]) + LIBS="$save_LIBS" + ]) + case "$gl_cv_func_hypotl_ieee" in + *yes) ;; + *) REPLACE_HYPOTL=1 ;; + esac + fi + ]) else HAVE_HYPOTL=0 + fi + if test $HAVE_HYPOTL = 0 || test $REPLACE_HYPOTL = 1; then dnl Find libraries needed to link lib/hypotl.c. if test $HAVE_SAME_LONG_DOUBLE_AS_DOUBLE = 1; then HYPOTL_LIBM="$HYPOT_LIBM"
--- a/m4/math_h.m4 +++ b/m4/math_h.m4 @@ -1,4 +1,4 @@ -# math_h.m4 serial 74 +# math_h.m4 serial 75 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, @@ -227,6 +227,7 @@ REPLACE_HUGE_VAL=0; AC_SUBST([REPLACE_HUGE_VAL]) REPLACE_HYPOT=0; AC_SUBST([REPLACE_HYPOT]) REPLACE_HYPOTF=0; AC_SUBST([REPLACE_HYPOTF]) + REPLACE_HYPOTL=0; AC_SUBST([REPLACE_HYPOTL]) REPLACE_ISFINITE=0; AC_SUBST([REPLACE_ISFINITE]) REPLACE_ISINF=0; AC_SUBST([REPLACE_ISINF]) REPLACE_ISNAN=0; AC_SUBST([REPLACE_ISNAN])
--- a/modules/hypotl +++ b/modules/hypotl @@ -8,17 +8,17 @@ Depends-on: math -hypot [test $HAVE_HYPOTL = 0 && test $HAVE_SAME_LONG_DOUBLE_AS_DOUBLE = 1] -isfinite [test $HAVE_HYPOTL = 0 && test $HAVE_SAME_LONG_DOUBLE_AS_DOUBLE = 0] -fabsl [test $HAVE_HYPOTL = 0 && test $HAVE_SAME_LONG_DOUBLE_AS_DOUBLE = 0] -frexpl [test $HAVE_HYPOTL = 0 && test $HAVE_SAME_LONG_DOUBLE_AS_DOUBLE = 0] -ldexpl [test $HAVE_HYPOTL = 0 && test $HAVE_SAME_LONG_DOUBLE_AS_DOUBLE = 0] -sqrtl [test $HAVE_HYPOTL = 0 && test $HAVE_SAME_LONG_DOUBLE_AS_DOUBLE = 0] -isinf [test $HAVE_HYPOTL = 0 && test $HAVE_SAME_LONG_DOUBLE_AS_DOUBLE = 0] +hypot [{ test $HAVE_HYPOTL = 0 || test $REPLACE_HYPOTL = 1; } && test $HAVE_SAME_LONG_DOUBLE_AS_DOUBLE = 1] +isfinite [{ test $HAVE_HYPOTL = 0 || test $REPLACE_HYPOTL = 1; } && test $HAVE_SAME_LONG_DOUBLE_AS_DOUBLE = 0] +fabsl [{ test $HAVE_HYPOTL = 0 || test $REPLACE_HYPOTL = 1; } && test $HAVE_SAME_LONG_DOUBLE_AS_DOUBLE = 0] +frexpl [{ test $HAVE_HYPOTL = 0 || test $REPLACE_HYPOTL = 1; } && test $HAVE_SAME_LONG_DOUBLE_AS_DOUBLE = 0] +ldexpl [{ test $HAVE_HYPOTL = 0 || test $REPLACE_HYPOTL = 1; } && test $HAVE_SAME_LONG_DOUBLE_AS_DOUBLE = 0] +sqrtl [{ test $HAVE_HYPOTL = 0 || test $REPLACE_HYPOTL = 1; } && test $HAVE_SAME_LONG_DOUBLE_AS_DOUBLE = 0] +isinf [{ test $HAVE_HYPOTL = 0 || test $REPLACE_HYPOTL = 1; } && test $HAVE_SAME_LONG_DOUBLE_AS_DOUBLE = 0] configure.ac: gl_FUNC_HYPOTL -if test $HAVE_HYPOTL = 0; then +if test $HAVE_HYPOTL = 0 || test $REPLACE_HYPOTL = 1; then AC_LIBOBJ([hypotl]) fi gl_MATH_MODULE_INDICATOR([hypotl])
--- a/modules/hypotl-ieee +++ b/modules/hypotl-ieee @@ -2,12 +2,15 @@ hypotl() function according to ISO C 99 with IEC 60559. Files: +m4/hypotl-ieee.m4 Depends-on: hypotl fpieee +hypot-ieee [{ test $HAVE_HYPOTL = 0 || test $REPLACE_HYPOTL = 1; } && test $HAVE_SAME_LONG_DOUBLE_AS_DOUBLE = 1] configure.ac: +gl_FUNC_HYPOTL_IEEE Makefile.am:
--- a/modules/math +++ b/modules/math @@ -196,6 +196,7 @@ -e 's|@''REPLACE_HUGE_VAL''@|$(REPLACE_HUGE_VAL)|g' \ -e 's|@''REPLACE_HYPOT''@|$(REPLACE_HYPOT)|g' \ -e 's|@''REPLACE_HYPOTF''@|$(REPLACE_HYPOTF)|g' \ + -e 's|@''REPLACE_HYPOTL''@|$(REPLACE_HYPOTL)|g' \ -e 's|@''REPLACE_ISFINITE''@|$(REPLACE_ISFINITE)|g' \ -e 's|@''REPLACE_ISINF''@|$(REPLACE_ISINF)|g' \ -e 's|@''REPLACE_ISNAN''@|$(REPLACE_ISNAN)|g' \