>From 9003e0a643aef003c8858db4936c3f57607d450b Mon Sep 17 00:00:00 2001 From: "A. Gordon" Date: Tue, 15 Apr 2014 11:58:11 -0400 Subject: [PATCH] m4: tests for buggy expl() implementations On some systems (OpenBSD 5.4), expl() incorrectly returns 'nan' for small values. Compare the result of exp() with expl(), and use Gnulib's expl if needed. --- m4/expl.m4 | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/m4/expl.m4 b/m4/expl.m4 index 247bc6e..1d78534 100644 --- a/m4/expl.m4 +++ b/m4/expl.m4 @@ -87,5 +87,36 @@ AC_DEFUN([gl_FUNC_EXPL], esac fi fi + dnl On some systems (OpenBSD5.4) the system's native expl() is buggy: + dnl it returns 'nan' for small values. This test compares expl() to exp() . + if test $gl_cv_func_expl_no_libm = yes \ + || test $gl_cv_func_expl_in_libm = yes; then + AC_CACHE_CHECK([checks whether expl is buggy], + [gl_cv_func_expl_buggy], + [ + save_LIBS="$LIBS" + LIBS="$EXPL_LIBM $FABS_LIBM" + AC_RUN_IFELSE( + [AC_LANG_PROGRAM( + [[#include +]], [[ double l ; + int expl_ok = 1 ; + for (l=-3 ; l < 3 ; l+=0.001) + expl_ok &= (fabs(exp(l)-expl(l))<1e-10); + return expl_ok?0:1 ; ]])], + [gl_cv_func_func_expl_buggy=no], [gl_cv_func_expl_buggy=yes], + [case $host_os in + mingw*) gl_cv_func_expl_buggy="guessing no";; + *) gl_cv_func_expl_buggy="guessing yes";; + esac]) + LIBS="$save_LIBS" + ]) + if test $gl_cv_func_expl_buggy = yes; then + dnl TODO: Use gnulib's expl instead of the system's expl + AC_MSG_NOTICE([Detected buggy expl(), using gnulib's implementatin]) + gl_cv_func_expl_in_libm=no + gl_cv_func_expl_no_libm=no + fi + fi AC_SUBST([EXPL_LIBM]) ]) -- 1.9.1