On 04/16/2014 04:44 PM, Assaf Gordon wrote:
> Hello,
> 
> On 04/15/2014 01:34 PM, Pádraig Brady wrote:
>> On 04/15/2014 05:18 PM, Assaf Gordon wrote:
>>> +  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() .
>>
>> You might assume that fabs is in the same lib as expl?
>> So this FABS_LIBM var is probably best left out,
>> as it's not guaranteed set here.
> <...>
>> Is checking this whole range necessary?
> <...>
>> s/in/ion/
> <...>
>> You could just move the whole block earlier in the function to line 55,
>> so that the subsequent check of $gl_cv_func_expl_in_libm etc. is significant?
>>
> 
> Attached is an improved version, changed according to your suggestions.
> It now uses Gnulib's expl on OpenBSD5.4, and the native expl on other systems.

Looks good.

I checked with:
  ./gnulib-tool --create-testdir --with-tests --test expl
and got this minor issue:
  checking checks whether expl is buggy...
  ../configure: line 9184: test: =: unary operator expected

I fixed that, removed the notice which seemed overkill in this context,
adjusted the Changelog, added some comments, fixed up the AC_CACHE_CHECK() 
message,
and added a little texi info.

I'll push the attached later.

thanks!
Pádraig.

>From 42aae83cdfa531f247ca38d2f3408bffd2177ce0 Mon Sep 17 00:00:00 2001
From: Assaf Gordon <agor...@wi.mit.edu>
Date: Wed, 16 Apr 2014 11:35:55 -0400
Subject: [PATCH] expl: avoid incorrect expl(small_value) on OpenBSD 5.4

OpenBSD 5.4, expl() incorrectly returns 'nan' for small values.
Detect this and use gnulib's expl() in that case.

Discussed here:
http://marc.info/?t=139159081700002&r=1&w=2
(Message from David Coppa on 2014-02-05 to openbsd-tech mailing list).

Fixed here (in revision 1.2):
http://www.openbsd.org/cgi-bin/cvsweb/src/lib/libm/src/ld128/s_floorl.c

* m4/expl.m4 (gl_FUNC_EXPL): Add a check for this condition.
* doc/posix-functions/expl.texi: Mention the workaround.
---
 ChangeLog                     |    6 ++++++
 doc/posix-functions/expl.texi |    3 +++
 m4/expl.m4                    |   27 +++++++++++++++++++++++++++
 3 files changed, 36 insertions(+), 0 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 6bf7c00..d4249b0 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2014-04-16  Assaf Gordon  <egg...@wi.mit.edu>
+
+	expl: avoid incorrect expl(small_value) on OpenBSD 5.4
+	* m4/expl.m4 (gl_FUNC_EXPL): Add a check for this condition.
+	* doc/posix-functions/expl.texi: Mention the workaround.
+
 2014-04-12  Paul Eggert  <egg...@cs.ucla.edu>
 
 	xalloc: allow x2nrealloc (P, PN, S) where P && !*PN
diff --git a/doc/posix-functions/expl.texi b/doc/posix-functions/expl.texi
index f198d00..633e684 100644
--- a/doc/posix-functions/expl.texi
+++ b/doc/posix-functions/expl.texi
@@ -12,6 +12,9 @@ Portability problems fixed by Gnulib:
 This function is missing on some platforms:
 FreeBSD 6.0, NetBSD 5.0, OpenBSD 3.8, Minix 3.1.8, HP-UX 11, IRIX 6.5, Solaris 9, Cygwin, Interix 3.5, BeOS.
 @item
+This function returns NaN for small operands:
+OpenBSD 5.4.
+@item
 This function is only defined as a macro with arguments on some platforms:
 MSVC 9.
 @item
diff --git a/m4/expl.m4 b/m4/expl.m4
index 247bc6e..3e41589 100644
--- a/m4/expl.m4
+++ b/m4/expl.m4
@@ -53,6 +53,33 @@ AC_DEFUN([gl_FUNC_EXPL],
       EXPL_LIBM=-lm
     fi
   fi
+  dnl On OpenBSD5.4 the system's native expl() is buggy:
+  dnl it returns 'nan' for small values. Test for this anomaly.
+  if test $gl_cv_func_expl_no_libm = yes \
+     || test $gl_cv_func_expl_in_libm = yes; then
+    AC_CACHE_CHECK([whether expl() breaks with small values],
+        [gl_cv_func_expl_buggy],
+        [
+          save_LIBS="$LIBS"
+          LIBS="$EXPL_LIBM"
+          AC_RUN_IFELSE(
+           [AC_LANG_PROGRAM(
+             [[#include <math.h>]],
+             [[return isnan(expl(-1.0))||
+                      isnan(expl(-0.8))||
+                      isnan(expl(-0.4)); ]])],
+             [gl_cv_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
+      gl_cv_func_expl_in_libm=no
+      gl_cv_func_expl_no_libm=no
+    fi
+  fi
   if test $gl_cv_func_expl_no_libm = yes \
      || test $gl_cv_func_expl_in_libm = yes; then
     dnl Also check whether it's declared.
-- 
1.7.7.6

Reply via email to