New module 'ldexpl'.
authorBruno Haible <bruno@clisp.org>
Fri, 30 Mar 2007 00:13:24 +0000 (00:13 +0000)
committerBruno Haible <bruno@clisp.org>
Fri, 30 Mar 2007 00:13:24 +0000 (00:13 +0000)
ChangeLog
lib/math_.h
m4/ldexpl.m4 [new file with mode: 0644]
m4/math_h.m4
m4/mathl.m4
m4/printf-frexpl.m4
modules/ldexpl [new file with mode: 0644]
modules/math
modules/mathl

index a5c2534..7c42d3b 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,21 @@
 2007-03-29  Bruno Haible  <bruno@clisp.org>
 
+       * modules/ldexpl: New file.
+       * m4/ldexpl.m4: New file.
+       * lib/math_.h (ldexpl): Define to a replacement if REPLACE_LDEXPL is
+       set.
+       * m4/math_h.m4 (gl_MATH_H_DEFAULTS): Initialize also GNULIB_LDEXPL,
+       REPLACE_LDEXPL.
+       * modules/math (Makefile.am): Substitute also GNULIB_LDEXPL,
+       REPLACE_LDEXPL.
+       * m4/printf-frexpl.m4 (gl_FUNC_PRINTF_FREXPL): Invoke
+       gl_FUNC_LDEXPL_WORKS.
+       * m4/mathl.m4 (gl_FUNC_LONG_DOUBLE_MATH): Remove test for ldexpl.
+       * modules/mathl (Files): Remove lib/ldexpl.c.
+       (Depends-on): Add ldexpl.
+
+2007-03-29  Bruno Haible  <bruno@clisp.org>
+
        * m4/frexpl.m4 (gl_FUNC_FREXPL_WORKS): Declare frexpl.
 
 2007-03-29  Bruno Haible  <bruno@clisp.org>
index 0fa81d7..e8dfb2a 100644 (file)
@@ -149,14 +149,18 @@ extern long double frexpl (long double x, int *exp);
      frexpl (x, e))
 #endif
 
-#if @GNULIB_MATHL@ || !@HAVE_DECL_LDEXPL@
+/* Return x * 2^exp.  */
+#if @GNULIB_LDEXPL@ && @REPLACE_LDEXPL@
+# define ldexpl rpl_ldexpl
+#endif
+#if (@GNULIB_LDEXPL@ && @REPLACE_LDEXPL@) || !@HAVE_DECL_LDEXPL@
 extern long double ldexpl (long double x, int exp);
 #endif
-#if !@GNULIB_MATHL@ && defined GNULIB_POSIXCHECK
+#if !@GNULIB_LDEXPL@ && defined GNULIB_POSIXCHECK
 # undef ldexpl
 # define ldexpl(x,e) \
     (GL_LINK_WARNING ("ldexpl is unportable - " \
-                      "use gnulib module mathl for portability"), \
+                      "use gnulib module ldexpl for portability"), \
      ldexpl (x, e))
 #endif
 
diff --git a/m4/ldexpl.m4 b/m4/ldexpl.m4
new file mode 100644 (file)
index 0000000..b7ef580
--- /dev/null
@@ -0,0 +1,83 @@
+# ldexpl.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,
+dnl with or without modifications, as long as this notice is preserved.
+
+AC_DEFUN([gl_FUNC_LDEXPL],
+[
+  AC_REQUIRE([gl_MATH_H_DEFAULTS])
+  LDEXPL_LIBM=
+  AC_CACHE_CHECK([whether ldexpl() can be used without linking with libm],
+    [gl_cv_func_ldexpl_no_libm],
+    [
+      AC_TRY_LINK([#include <math.h>
+                   long double x;],
+                  [return ldexpl (x, -1) > 0;],
+        [gl_cv_func_ldexpl_no_libm=yes],
+        [gl_cv_func_ldexpl_no_libm=no])
+    ])
+  if test $gl_cv_func_ldexpl_no_libm = no; then
+    AC_CACHE_CHECK([whether ldexpl() can be used with libm],
+      [gl_cv_func_ldexpl_in_libm],
+      [
+        save_LIBS="$LIBS"
+        LIBS="$LIBS -lm"
+        AC_TRY_LINK([#include <math.h>
+                     long double x;],
+                    [return ldexpl (x, -1) > 0;],
+          [gl_cv_func_ldexpl_in_libm=yes],
+          [gl_cv_func_ldexpl_in_libm=no])
+        LIBS="$save_LIBS"
+      ])
+    if test $gl_cv_func_ldexpl_in_libm = yes; then
+      LDEXPL_LIBM=-lm
+    fi
+  fi
+  if test $gl_cv_func_ldexpl_no_libm = yes \
+     || test $gl_cv_func_ldexpl_in_libm = yes; then
+    save_LIBS="$LIBS"
+    LIBS="$LIBS $LDEXPL_LIBM"
+    gl_FUNC_LDEXPL_WORKS
+    LIBS="$save_LIBS"
+    case "$gl_cv_func_ldexpl_works" in
+      *yes) gl_func_ldexpl=yes ;;
+      *)    gl_func_ldexpl=no; REPLACE_LDEXPL=1; LDEXPL_LIBM= ;;
+    esac
+  else
+    gl_func_ldexpl=no
+  fi
+  if test $gl_func_ldexpl = yes; then
+    AC_DEFINE([HAVE_LDEXPL], 1,
+      [Define if the ldexpl() function is available.])
+    dnl Also check whether it's declared.
+    dnl MacOS X 10.3 has ldexpl() in libc but doesn't declare it in <math.h>.
+    AC_CHECK_DECL([ldexpl], , [HAVE_DECL_LDEXPL=0], [#include <math.h>])
+  else
+    AC_LIBOBJ([ldexpl])
+  fi
+])
+
+dnl Test whether ldexpl() works on finite numbers (this fails on AIX 5.1).
+AC_DEFUN([gl_FUNC_LDEXPL_WORKS],
+[
+  AC_REQUIRE([AC_PROG_CC])
+  AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
+  AC_CACHE_CHECK([whether ldexpl works], [gl_cv_func_ldexpl_works],
+    [
+      AC_TRY_RUN([
+#include <math.h>
+extern long double ldexpl (long double, int);
+int main()
+{
+  volatile long double x = 1.0;
+  volatile long double y = ldexpl (x, -1);
+  return (y != 0.5L);
+}], [gl_cv_func_ldexpl_works=yes], [gl_cv_func_ldexpl_works=no],
+      [case "$host_os" in
+         aix*) gl_cv_func_ldexpl_works="guessing no";;
+         *)    gl_cv_func_ldexpl_works="guessing yes";;
+       esac
+      ])
+    ])
+])
index cc906f6..1202dc8 100644 (file)
@@ -1,4 +1,4 @@
-# math_h.m4 serial 3
+# math_h.m4 serial 4
 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,
@@ -23,6 +23,7 @@ AC_DEFUN([gl_MATH_H_DEFAULTS],
 [
   GNULIB_FREXP=0;  AC_SUBST([GNULIB_FREXP])
   GNULIB_FREXPL=0; AC_SUBST([GNULIB_FREXPL])
+  GNULIB_LDEXPL=0; AC_SUBST([GNULIB_LDEXPL])
   GNULIB_MATHL=0;  AC_SUBST([GNULIB_MATHL])
   dnl Assume proper GNU behavior unless another module says otherwise.
   HAVE_DECL_ACOSL=1;  AC_SUBST([HAVE_DECL_ACOSL])
@@ -40,4 +41,5 @@ AC_DEFUN([gl_MATH_H_DEFAULTS],
   HAVE_DECL_TANL=1;   AC_SUBST([HAVE_DECL_TANL])
   REPLACE_FREXP=0;    AC_SUBST([REPLACE_FREXP])
   REPLACE_FREXPL=0;   AC_SUBST([REPLACE_FREXPL])
+  REPLACE_LDEXPL=0;   AC_SUBST([REPLACE_LDEXPL])
 ])
index 57d70a5..5d82466 100644 (file)
@@ -1,4 +1,4 @@
-# mathl.m4 serial 3
+# mathl.m4 serial 4
 dnl Copyright (c) 2003, 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,
@@ -7,7 +7,7 @@ dnl with or without modifications, as long as this notice is preserved.
 AC_DEFUN([gl_FUNC_LONG_DOUBLE_MATH], [
 
 AC_CHECK_LIB(m, atan)
-AC_REPLACE_FUNCS(floorl ceill sqrtl ldexpl asinl acosl atanl \
+AC_REPLACE_FUNCS(floorl ceill sqrtl asinl acosl atanl \
         logl expl tanl sinl cosl)
 
 ])
index d522d0e..14acc35 100644 (file)
@@ -40,11 +40,16 @@ AC_DEFUN([gl_FUNC_PRINTF_FREXPL],
           [gl_cv_func_ldexpl_no_libm=no])
       ])
     if test $gl_cv_func_ldexpl_no_libm = yes; then
-      AC_DEFINE([HAVE_LDEXPL_IN_LIBC], 1,
-        [Define if the ldexpl function is available in libc.])
-      dnl Also check whether it's declared.
-      dnl MacOS X 10.3 has ldexpl() in libc but doesn't declare it in <math.h>.
-      AC_CHECK_DECL([ldexpl], , [HAVE_DECL_LDEXPL=0], [#include <math.h>])
+      gl_FUNC_LDEXPL_WORKS
+      case "$gl_cv_func_ldexpl_works" in
+        *yes)
+          AC_DEFINE([HAVE_LDEXPL_IN_LIBC], 1,
+            [Define if the ldexpl function is available in libc.])
+          dnl Also check whether it's declared.
+          dnl MacOS X 10.3 has ldexpl() in libc but doesn't declare it in <math.h>.
+          AC_CHECK_DECL([ldexpl], , [HAVE_DECL_LDEXPL=0], [#include <math.h>])
+          ;;
+      esac
     fi
   fi
 ])
diff --git a/modules/ldexpl b/modules/ldexpl
new file mode 100644 (file)
index 0000000..c89187a
--- /dev/null
@@ -0,0 +1,26 @@
+Description:
+ldexpl() function: multiply a 'long double' by a power of 2.
+
+Files:
+lib/ldexpl.c
+m4/ldexpl.m4
+
+Depends-on:
+math
+isnanl-nolibm
+
+configure.ac:
+gl_FUNC_LDEXPL
+gl_MATH_MODULE_INDICATOR([ldexpl])
+
+Makefile.am:
+
+Include:
+<math.h>
+
+License:
+LGPL
+
+Maintainer:
+Bruno Haible, Paolo Bonzini
+
index 5c28af7..eb72003 100644 (file)
@@ -23,6 +23,7 @@ math.h: math_.h
          sed -e 's|@''ABSOLUTE_MATH_H''@|$(ABSOLUTE_MATH_H)|g' \
              -e 's|@''GNULIB_FREXP''@|$(GNULIB_FREXP)|g' \
              -e 's|@''GNULIB_FREXPL''@|$(GNULIB_FREXPL)|g' \
+             -e 's|@''GNULIB_LDEXPL''@|$(GNULIB_LDEXPL)|g' \
              -e 's|@''GNULIB_MATHL''@|$(GNULIB_MATHL)|g' \
              -e 's|@''HAVE_DECL_ACOSL''@|$(HAVE_DECL_ACOSL)|g' \
              -e 's|@''HAVE_DECL_ASINL''@|$(HAVE_DECL_ASINL)|g' \
@@ -39,6 +40,7 @@ math.h: math_.h
              -e 's|@''HAVE_DECL_TANL''@|$(HAVE_DECL_TANL)|g' \
              -e 's|@''REPLACE_FREXP''@|$(REPLACE_FREXP)|g' \
              -e 's|@''REPLACE_FREXPL''@|$(REPLACE_FREXPL)|g' \
+             -e 's|@''REPLACE_LDEXPL''@|$(REPLACE_LDEXPL)|g' \
              -e '/definition of GL_LINK_WARNING/r $(LINK_WARNING_H)' \
              < $(srcdir)/math_.h; \
        } > $@-t
index 709f21e..d9c1b13 100644 (file)
@@ -9,7 +9,6 @@ lib/ceill.c
 lib/cosl.c
 lib/expl.c
 lib/floorl.c
-lib/ldexpl.c
 lib/logl.c
 lib/sincosl.c
 lib/sinl.c
@@ -23,6 +22,7 @@ Depends-on:
 math
 frexpl
 isnanl
+ldexpl
 
 configure.ac:
 gl_FUNC_LONG_DOUBLE_MATH