bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: new module 'cbrtl'


From: Bruno Haible
Subject: Re: new module 'cbrtl'
Date: Wed, 14 Mar 2012 00:40:48 +0100
User-agent: KMail/4.7.4 (Linux/3.1.0-1.2-desktop; KDE/4.7.4; x86_64; ; )

> 2012-02-29  Bruno Haible  <address@hidden>
> 
>       New module 'cbrtl'.
>       * lib/math.in.h (cbrtl): New declaration.
>       * lib/cbrtl.c: New file.
>       * m4/cbrtl.m4: New file.
>       * m4/math_h.m4 (gl_MATH_H): Test whether cbrtl is declared.
>       (gl_MATH_H_DEFAULTS): Initialize GNULIB_CBRTL, HAVE_CBRTL,
>       HAVE_DECL_CBRTL.
>       * modules/math (Makefile.am): Substitute GNULIB_CBRTL, HAVE_CBRTL,
>       HAVE_DECL_CBRTL.
>       * modules/cbrtl: New file.
>       * tests/test-math-c++.cc: Check the declaration of cbrtl.
>       * doc/posix-functions/cbrtl.texi: Mention the new module.

The tests fail on OpenBSD 5.1/SPARC:

test-cbrt.h:39: assertion failed
FAIL: test-cbrtl

cbrtl(16.0L) returns 1.2599..., which is obviously completely broken.

Here's the workaround:


2012-03-13  Bruno Haible  <address@hidden>

        cbrtl: Bypass broken implementation in OpenBSD 5.1/SPARC.
        * m4/cbrtl.m4 (gl_FUNC_CBRTL_WORKS): New macro.
        (gl_FUNC_CBRTL): Invoke it. If the function does not work, set
        REPLACE_CBRTL to 1.
        * doc/posix-functions/cbrtl.texi: Mention the OpenBSD 5.1/SPARC bug.

--- doc/posix-functions/cbrtl.texi.orig Wed Mar 14 00:36:43 2012
+++ doc/posix-functions/cbrtl.texi      Wed Mar 14 00:28:42 2012
@@ -14,6 +14,9 @@
 @item
 This function is not declared on some platforms:
 IRIX 6.5.
address@hidden
+This function produces grossly wrong results on some platforms:
+OpenBSD 5.1/SPARC.
 @end itemize
 
 Portability problems fixed by Gnulib module @code{cbrtl-ieee}:
--- m4/cbrtl.m4.orig    Wed Mar 14 00:36:43 2012
+++ m4/cbrtl.m4 Wed Mar 14 00:33:31 2012
@@ -1,4 +1,4 @@
-# cbrtl.m4 serial 3
+# cbrtl.m4 serial 4
 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,
@@ -25,6 +25,16 @@
     dnl Also check whether it's declared.
     dnl IRIX 6.5 has cbrtl() in libm but doesn't declare it in <math.h>.
     AC_CHECK_DECL([cbrtl], , [HAVE_DECL_CBRTL=0], [[#include <math.h>]])
+
+    save_LIBS="$LIBS"
+    LIBS="$LIBS $CBRTL_LIBM"
+    gl_FUNC_CBRTL_WORKS
+    LIBS="$save_LIBS"
+    case "$gl_cv_func_cbrtl_works" in
+      *yes) ;;
+      *) REPLACE_CBRTL=1 ;;
+    esac
+
     m4_ifdef([gl_FUNC_CBRTL_IEEE], [
       if test $gl_cbrtl_required = ieee && test $REPLACE_CBRTL = 0; then
         AC_CACHE_CHECK([whether cbrtl works according to ISO C 99 with IEC 
60559],
@@ -95,3 +105,40 @@
   fi
   AC_SUBST([CBRTL_LIBM])
 ])
+
+dnl Test whether cbrtl() works.
+dnl On OpenBSD 5.1/SPARC, cbrtl(16.0L) is = 1.2599...
+AC_DEFUN([gl_FUNC_CBRTL_WORKS],
+[
+  AC_REQUIRE([AC_PROG_CC])
+  AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
+  AC_CACHE_CHECK([whether cbrtl works], [gl_cv_func_cbrtl_works],
+    [
+      AC_RUN_IFELSE(
+        [AC_LANG_SOURCE([[
+#include <math.h>
+extern
+#ifdef __cplusplus
+"C"
+#endif
+long double cbrtl (long double);
+volatile long double x;
+long double y;
+int main ()
+{
+  x = 16.0L;
+  y = cbrtl (x);
+  if (y < 2.0L)
+    return 1;
+  return 0;
+}
+]])],
+        [gl_cv_func_cbrtl_works=yes],
+        [gl_cv_func_cbrtl_works=no],
+        [case "$host_os" in
+           osf*) gl_cv_func_cbrtl_works="guessing no";;
+           *)    gl_cv_func_cbrtl_works="guessing yes";;
+         esac
+        ])
+    ])
+])




reply via email to

[Prev in Thread] Current Thread [Next in Thread]