>From 0ac7b4317dbe2247c520d0f786926e9e520ba81c Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Sun, 20 Jan 2019 22:04:01 +0100 Subject: [PATCH 2/6] expl: Work around inaccurate implementation on NetBSD. * lib/math.in.h (expl): Test also REPLACE_EXPL. * m4/expl.m4 (gl_FUNC_EXPL): Add test for a certain accuracy. Set REPLACE_EXPL. * m4/math_h.m4 (gl_MATH_H_DEFAULTS): Initialize REPLACE_EXPL. * modules/math (Makefile.in): Substitute REPLACE_EXPL. * modules/expl (Depends-on, configure.ac): Test REPLACE_EXPL. * doc/posix-functions/expl.texi: Mention the NetBSD bug. --- ChangeLog | 11 ++++++ doc/posix-functions/expl.texi | 4 ++ lib/math.in.h | 15 +++++-- m4/expl.m4 | 92 ++++++++++++++++++++++++++++++++++++++++++- m4/math_h.m4 | 3 +- modules/expl | 12 +++--- modules/math | 1 + 7 files changed, 127 insertions(+), 11 deletions(-) diff --git a/ChangeLog b/ChangeLog index a8c6797..80f00e2 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,16 @@ 2019-01-20 Bruno Haible + expl: Work around inaccurate implementation on NetBSD. + * lib/math.in.h (expl): Test also REPLACE_EXPL. + * m4/expl.m4 (gl_FUNC_EXPL): Add test for a certain accuracy. Set + REPLACE_EXPL. + * m4/math_h.m4 (gl_MATH_H_DEFAULTS): Initialize REPLACE_EXPL. + * modules/math (Makefile.in): Substitute REPLACE_EXPL. + * modules/expl (Depends-on, configure.ac): Test REPLACE_EXPL. + * doc/posix-functions/expl.texi: Mention the NetBSD bug. + +2019-01-20 Bruno Haible + exp2l: Work around inaccurate implementation on NetBSD. * m4/exp2l.m4 (gl_FUNC_EXP2L): Add test for a certain accuracy. * doc/posix-functions/exp2l.texi: Mention the NetBSD bug. diff --git a/doc/posix-functions/expl.texi b/doc/posix-functions/expl.texi index 2e5d086..4a3ffdd 100644 --- a/doc/posix-functions/expl.texi +++ b/doc/posix-functions/expl.texi @@ -23,6 +23,10 @@ MSVC 14. @item This function is not declared on some platforms: Mac OS X 10.3. address@hidden +This function produces results which are accurate to only 16 digits on some +platforms: +NetBSD 8.0. @end itemize Portability problems not fixed by Gnulib: diff --git a/lib/math.in.h b/lib/math.in.h index d395552..c5f9b46 100644 --- a/lib/math.in.h +++ b/lib/math.in.h @@ -627,11 +627,20 @@ _GL_WARN_ON_USE (expf, "expf is unportable - " #endif #if @GNULIB_EXPL@ -# if address@hidden@ || address@hidden@ -# undef expl +# if @REPLACE_EXPL@ +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# undef expl +# define expl rpl_expl +# endif +_GL_FUNCDECL_RPL (expl, long double, (long double x)); +_GL_CXXALIAS_RPL (expl, long double, (long double x)); +# else +# if address@hidden@ || address@hidden@ +# undef expl _GL_FUNCDECL_SYS (expl, long double, (long double x)); -# endif +# endif _GL_CXXALIAS_SYS (expl, long double, (long double x)); +# endif _GL_CXXALIASWARN (expl); #elif defined GNULIB_POSIXCHECK # undef expl diff --git a/m4/expl.m4 b/m4/expl.m4 index 93851a2..c04c1cb 100644 --- a/m4/expl.m4 +++ b/m4/expl.m4 @@ -1,4 +1,4 @@ -# expl.m4 serial 11 +# expl.m4 serial 12 dnl Copyright (C) 2010-2019 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, @@ -96,9 +96,99 @@ AC_DEFUN([gl_FUNC_EXPL], dnl Also check whether it's declared. dnl Mac OS X 10.3 has expl() in libc but doesn't declare it in . AC_CHECK_DECL([expl], , [HAVE_DECL_EXPL=0], [[#include ]]) + if test $REPLACE_EXPL = 0; then + AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles + AC_CACHE_CHECK([whether expl works], + [gl_cv_func_expl_works], + [ + save_LIBS="$LIBS" + LIBS="$LIBS $EXPL_LIBM" + AC_RUN_IFELSE( + [AC_LANG_SOURCE([[ +#ifndef __NO_MATH_INLINES +# define __NO_MATH_INLINES 1 /* for glibc */ +#endif +#include +#include +/* Override the values of , like done in float.in.h. */ +#if defined __i386__ && (defined __BEOS__ || defined __OpenBSD__) +# undef LDBL_MANT_DIG +# define LDBL_MANT_DIG 64 +# undef LDBL_MIN_EXP +# define LDBL_MIN_EXP (-16381) +# undef LDBL_MAX_EXP +# define LDBL_MAX_EXP 16384 +#endif +#if defined __i386__ && (defined __FreeBSD__ || defined __DragonFly__) +# undef LDBL_MANT_DIG +# define LDBL_MANT_DIG 64 +# undef LDBL_MIN_EXP +# define LDBL_MIN_EXP (-16381) +# undef LDBL_MAX_EXP +# define LDBL_MAX_EXP 16384 +#endif +#if (defined _ARCH_PPC || defined _POWER) && defined _AIX && (LDBL_MANT_DIG == 106) && defined __GNUC__ +# undef LDBL_MIN_EXP +# define LDBL_MIN_EXP DBL_MIN_EXP +#endif +#if defined __sgi && (LDBL_MANT_DIG >= 106) +# undef LDBL_MANT_DIG +# define LDBL_MANT_DIG 106 +# if defined __GNUC__ +# undef LDBL_MIN_EXP +# define LDBL_MIN_EXP DBL_MIN_EXP +# endif +#endif +#undef expl +extern +#ifdef __cplusplus +"C" +#endif +long double expl (long double); +static long double dummy (long double x) { return 0; } +int main (int argc, char *argv[]) +{ + long double (* volatile my_expl) (long double) = argc ? expl : dummy; + int result = 0; + /* This test fails on NetBSD 8.0. */ + { + const long double TWO_LDBL_MANT_DIG = /* 2^LDBL_MANT_DIG */ + (long double) (1U << ((LDBL_MANT_DIG - 1) / 5)) + * (long double) (1U << ((LDBL_MANT_DIG - 1 + 1) / 5)) + * (long double) (1U << ((LDBL_MANT_DIG - 1 + 2) / 5)) + * (long double) (1U << ((LDBL_MANT_DIG - 1 + 3) / 5)) + * (long double) (1U << ((LDBL_MANT_DIG - 1 + 4) / 5)); + long double x = 11.358L; + long double err = (my_expl (x) * my_expl (- x) - 1.0L) * TWO_LDBL_MANT_DIG; + if (!(err >= -100.0L && err <= 100.0L)) + result |= 1; + } + return result; +} + ]])], + [gl_cv_func_expl_works=yes], + [gl_cv_func_expl_works=no], + [case "$host_os" in + # Guess yes on glibc systems. + *-gnu* | gnu*) gl_cv_func_expl_works="guessing yes" ;; + # Guess yes on native Windows. + mingw*) gl_cv_func_expl_works="guessing yes" ;; + # If we don't know, assume the worst. + *) gl_cv_func_expl_works="guessing no" ;; + esac + ]) + LIBS="$save_LIBS" + ]) + case "$gl_cv_func_expl_works" in + *yes) ;; + *) REPLACE_EXPL=1 ;; + esac + fi else HAVE_DECL_EXPL=0 HAVE_EXPL=0 + fi + if test $HAVE_EXPL = 0 || test $REPLACE_EXPL = 1; then dnl Find libraries needed to link lib/expl.c. if test $HAVE_SAME_LONG_DOUBLE_AS_DOUBLE = 1; then AC_REQUIRE([gl_FUNC_EXP]) diff --git a/m4/math_h.m4 b/m4/math_h.m4 index 7e79831..2eec8c4 100644 --- a/m4/math_h.m4 +++ b/m4/math_h.m4 @@ -1,4 +1,4 @@ -# math_h.m4 serial 116 +# math_h.m4 serial 117 dnl Copyright (C) 2007-2019 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, @@ -268,6 +268,7 @@ AC_DEFUN([gl_MATH_H_DEFAULTS], REPLACE_COSF=0; AC_SUBST([REPLACE_COSF]) REPLACE_COSHF=0; AC_SUBST([REPLACE_COSHF]) REPLACE_EXPF=0; AC_SUBST([REPLACE_EXPF]) + REPLACE_EXPL=0; AC_SUBST([REPLACE_EXPL]) REPLACE_EXPM1=0; AC_SUBST([REPLACE_EXPM1]) REPLACE_EXPM1F=0; AC_SUBST([REPLACE_EXPM1F]) REPLACE_EXP2=0; AC_SUBST([REPLACE_EXP2]) diff --git a/modules/expl b/modules/expl index 32ee6c0..90a7e65 100644 --- a/modules/expl +++ b/modules/expl @@ -9,15 +9,15 @@ m4/expl.m4 Depends-on: math extensions -exp [test $HAVE_EXPL = 0 && test $HAVE_SAME_LONG_DOUBLE_AS_DOUBLE = 1] -float [test $HAVE_EXPL = 0 && test $HAVE_SAME_LONG_DOUBLE_AS_DOUBLE = 0] -isnanl [test $HAVE_EXPL = 0 && test $HAVE_SAME_LONG_DOUBLE_AS_DOUBLE = 0] -roundl [test $HAVE_EXPL = 0 && test $HAVE_SAME_LONG_DOUBLE_AS_DOUBLE = 0] -ldexpl [test $HAVE_EXPL = 0 && test $HAVE_SAME_LONG_DOUBLE_AS_DOUBLE = 0] +exp [{ test $HAVE_EXPL = 0 || test $REPLACE_EXPL = 1; } && test $HAVE_SAME_LONG_DOUBLE_AS_DOUBLE = 1] +float [{ test $HAVE_EXPL = 0 || test $REPLACE_EXPL = 1; } && test $HAVE_SAME_LONG_DOUBLE_AS_DOUBLE = 0] +isnanl [{ test $HAVE_EXPL = 0 || test $REPLACE_EXPL = 1; } && test $HAVE_SAME_LONG_DOUBLE_AS_DOUBLE = 0] +roundl [{ test $HAVE_EXPL = 0 || test $REPLACE_EXPL = 1; } && test $HAVE_SAME_LONG_DOUBLE_AS_DOUBLE = 0] +ldexpl [{ test $HAVE_EXPL = 0 || test $REPLACE_EXPL = 1; } && test $HAVE_SAME_LONG_DOUBLE_AS_DOUBLE = 0] configure.ac: gl_FUNC_EXPL -if test $HAVE_EXPL = 0; then +if test $HAVE_EXPL = 0 || test $REPLACE_EXPL = 1; then AC_LIBOBJ([expl]) AC_LIBOBJ([expl-table]) fi diff --git a/modules/math b/modules/math index d539518..77197e5 100644 --- a/modules/math +++ b/modules/math @@ -237,6 +237,7 @@ math.h: math.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(ARG_NONNULL_H) $( -e 's|@''REPLACE_COSF''@|$(REPLACE_COSF)|g' \ -e 's|@''REPLACE_COSHF''@|$(REPLACE_COSHF)|g' \ -e 's|@''REPLACE_EXPF''@|$(REPLACE_EXPF)|g' \ + -e 's|@''REPLACE_EXPL''@|$(REPLACE_EXPL)|g' \ -e 's|@''REPLACE_EXPM1''@|$(REPLACE_EXPM1)|g' \ -e 's|@''REPLACE_EXPM1F''@|$(REPLACE_EXPM1F)|g' \ -e 's|@''REPLACE_EXP2''@|$(REPLACE_EXP2)|g' \ -- 2.7.4