changeset 28238:789087a972bd

Provide a replacement for frexpl() if the system has it but it doesn't work.
author Bruno Haible <bruno@clisp.org>
date Sun, 25 Mar 2007 21:35:38 +0000
parents 3808e174ce59
children 8c0795a6c272
files ChangeLog lib/math_.h m4/frexpl.m4 m4/math_h.m4 modules/math
diffstat 5 files changed, 60 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Sun Mar 25 21:25:35 2007 +0000
+++ b/ChangeLog	Sun Mar 25 21:35:38 2007 +0000
@@ -1,3 +1,13 @@
+2007-03-25  Bruno Haible  <bruno@clisp.org>
+
+	* m4/frexpl.m4 (gl_FUNC_FREXPL_WORKS): New macro.
+	(gl_FUNC_FREXPL): Invoke it. Set REPLACE_FREXPL to 1 if it frexpl
+	exists but doesn't work.
+	* lib/math_.h (frexpl): Define as a replacement macro if REPLACE_FREXPL
+	is set. Don't provide a prototype if REPLACE_FREXPL is not set.
+	* m4/math_h.m4 (gl_MATH_H_DEFAULTS): Initialize REPLACE_FREXPL.
+	* modules/math (Makefile.am) Substibute also REPLACE_FREXPL into math.h.
+
 2007-03-25  Bruno Haible  <bruno@clisp.org>
 
 	* m4/frexp.m4 (gl_FUNC_FREXP_WORKS): Add check whether frexp(inf)
--- a/lib/math_.h	Sun Mar 25 21:25:35 2007 +0000
+++ b/lib/math_.h	Sun Mar 25 21:35:38 2007 +0000
@@ -135,7 +135,10 @@
      If x is zero: mantissa = x, exp = 0.
      If x is infinite or NaN: mantissa = x, exp unspecified.
    Store exp and return mantissa.  */
-#if @GNULIB_FREXPL@ || !@HAVE_DECL_FREXPL@
+#if @GNULIB_FREXPL@ && @REPLACE_FREXPL@
+# define frexpl rpl_frexpl
+#endif
+#if (@GNULIB_FREXPL@ && @REPLACE_FREXPL@) || !@HAVE_DECL_FREXPL@
 extern long double frexpl (long double x, int *exp);
 #endif
 #if !@GNULIB_FREXPL@ && defined GNULIB_POSIXCHECK
--- a/m4/frexpl.m4	Sun Mar 25 21:25:35 2007 +0000
+++ b/m4/frexpl.m4	Sun Mar 25 21:35:38 2007 +0000
@@ -1,4 +1,4 @@
-# frexpl.m4 serial 1
+# frexpl.m4 serial 2
 dnl Copyright (C) 2007 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -36,6 +36,18 @@
   fi
   if test $gl_cv_func_frexpl_no_libm = yes \
      || test $gl_cv_func_frexpl_in_libm = yes; then
+    save_LIBS="$LIBS"
+    LIBS="$LIBS $FREXPL_LIBM"
+    gl_FUNC_FREXPL_WORKS
+    LIBS="$save_LIBS"
+    case "$gl_cv_func_frexpl_works" in
+      *yes) gl_func_frexpl=yes ;;
+      *)    gl_func_frexpl=no; REPLACE_FREXPL=1; FREXPL_LIBM= ;;
+    esac
+  else
+    gl_func_frexpl=no
+  fi
+  if test $gl_func_frexpl = yes; then
     AC_DEFINE([HAVE_FREXPL], 1,
       [Define if the frexpl() function is available.])
     dnl Also check whether it's declared.
@@ -45,3 +57,34 @@
     AC_LIBOBJ([frexpl])
   fi
 ])
+
+dnl Test whether frexpl() works also on infinite numbers (this fails e.g. on
+dnl IRIX 6.5).
+AC_DEFUN([gl_FUNC_FREXPL_WORKS],
+[
+  AC_REQUIRE([AC_PROG_CC])
+  AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
+  AC_CACHE_CHECK([whether frexpl works], [gl_cv_func_frexpl_works],
+    [
+      AC_TRY_RUN([
+#include <math.h>
+int main()
+{
+  volatile long double x;
+  /* Test on infinite numbers.  */
+  {
+    x = 1.0L / 0.0L;
+    int exp;
+    long double y = frexpl (x, &exp);
+    if (y != x)
+      return 1;
+  }
+  return 0;
+}], [gl_cv_func_frexpl_works=yes], [gl_cv_func_frexpl_works=no],
+      [case "$host_os" in
+         irix*) gl_cv_func_frexpl_works="guessing no";;
+         *)     gl_cv_func_frexpl_works="guessing yes";;
+       esac
+      ])
+    ])
+])
--- a/m4/math_h.m4	Sun Mar 25 21:25:35 2007 +0000
+++ b/m4/math_h.m4	Sun Mar 25 21:35:38 2007 +0000
@@ -39,4 +39,5 @@
   HAVE_DECL_SQRTL=1;  AC_SUBST([HAVE_DECL_SQRTL])
   HAVE_DECL_TANL=1;   AC_SUBST([HAVE_DECL_TANL])
   REPLACE_FREXP=0;    AC_SUBST([REPLACE_FREXP])
+  REPLACE_FREXPL=0;   AC_SUBST([REPLACE_FREXPL])
 ])
--- a/modules/math	Sun Mar 25 21:25:35 2007 +0000
+++ b/modules/math	Sun Mar 25 21:35:38 2007 +0000
@@ -38,6 +38,7 @@
 	      -e 's|@''HAVE_DECL_SQRTL''@|$(HAVE_DECL_SQRTL)|g' \
 	      -e 's|@''HAVE_DECL_TANL''@|$(HAVE_DECL_TANL)|g' \
 	      -e 's|@''REPLACE_FREXP''@|$(REPLACE_FREXP)|g' \
+	      -e 's|@''REPLACE_FREXPL''@|$(REPLACE_FREXPL)|g' \
 	      -e '/definition of GL_LINK_WARNING/r $(LINK_WARNING_H)' \
 	      < $(srcdir)/math_.h; \
 	} > $@-t