NEWS.stable: update
[gnulib.git] / m4 / ldexpl.m4
1 # ldexpl.m4 serial 10
2 dnl Copyright (C) 2007-2011 Free Software Foundation, Inc.
3 dnl This file is free software; the Free Software Foundation
4 dnl gives unlimited permission to copy and/or distribute it,
5 dnl with or without modifications, as long as this notice is preserved.
6
7 AC_DEFUN([gl_FUNC_LDEXPL],
8 [
9   AC_REQUIRE([gl_MATH_H_DEFAULTS])
10   AC_REQUIRE([gl_FUNC_ISNANL]) dnl for ISNANL_LIBM
11   dnl Check whether it's declared.
12   dnl MacOS X 10.3 has ldexpl() in libc but doesn't declare it in <math.h>.
13   AC_CHECK_DECL([ldexpl], , [HAVE_DECL_LDEXPL=0], [#include <math.h>])
14   LDEXPL_LIBM=
15   if test $HAVE_DECL_LDEXPL = 1; then
16     gl_CHECK_LDEXPL_NO_LIBM
17     if test $gl_cv_func_ldexpl_no_libm = no; then
18       AC_CACHE_CHECK([whether ldexpl() can be used with libm],
19         [gl_cv_func_ldexpl_in_libm],
20         [
21           save_LIBS="$LIBS"
22           LIBS="$LIBS -lm"
23           AC_LINK_IFELSE(
24             [AC_LANG_PROGRAM(
25                [[#include <math.h>
26                  long double x;]],
27                [[return ldexpl (x, -1) > 0;]])],
28             [gl_cv_func_ldexpl_in_libm=yes],
29             [gl_cv_func_ldexpl_in_libm=no])
30           LIBS="$save_LIBS"
31         ])
32       if test $gl_cv_func_ldexpl_in_libm = yes; then
33         LDEXPL_LIBM=-lm
34       fi
35     fi
36     if test $gl_cv_func_ldexpl_no_libm = yes \
37        || test $gl_cv_func_ldexpl_in_libm = yes; then
38       save_LIBS="$LIBS"
39       LIBS="$LIBS $LDEXPL_LIBM"
40       gl_FUNC_LDEXPL_WORKS
41       LIBS="$save_LIBS"
42       case "$gl_cv_func_ldexpl_works" in
43         *yes) gl_func_ldexpl=yes ;;
44         *)    gl_func_ldexpl=no; REPLACE_LDEXPL=1 ;;
45       esac
46     else
47       gl_func_ldexpl=no
48     fi
49     if test $gl_func_ldexpl = yes; then
50       AC_DEFINE([HAVE_LDEXPL], [1],
51         [Define if the ldexpl() function is available.])
52     fi
53   fi
54   if test $HAVE_DECL_LDEXPL = 0 || test $gl_func_ldexpl = no; then
55     AC_LIBOBJ([ldexpl])
56     LDEXPL_LIBM="$ISNANL_LIBM"
57   fi
58   AC_SUBST([LDEXPL_LIBM])
59 ])
60
61 dnl Test whether ldexpl() can be used without linking with libm.
62 dnl Set gl_cv_func_ldexpl_no_libm to 'yes' or 'no' accordingly.
63 AC_DEFUN([gl_CHECK_LDEXPL_NO_LIBM],
64 [
65   AC_CACHE_CHECK([whether ldexpl() can be used without linking with libm],
66     [gl_cv_func_ldexpl_no_libm],
67     [
68       AC_LINK_IFELSE(
69         [AC_LANG_PROGRAM(
70            [[#include <math.h>
71              long double x;]],
72            [[return ldexpl (x, -1) > 0;]])],
73         [gl_cv_func_ldexpl_no_libm=yes],
74         [gl_cv_func_ldexpl_no_libm=no])
75     ])
76 ])
77
78 dnl Test whether ldexpl() works on finite numbers (this fails on AIX 5.1
79 dnl and MacOS X 10.4/PowerPC).
80 AC_DEFUN([gl_FUNC_LDEXPL_WORKS],
81 [
82   AC_REQUIRE([AC_PROG_CC])
83   AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
84   AC_CACHE_CHECK([whether ldexpl works], [gl_cv_func_ldexpl_works],
85     [
86       AC_RUN_IFELSE(
87         [AC_LANG_SOURCE([[
88 #include <math.h>
89 extern long double ldexpl (long double, int);
90 int main()
91 {
92   int result = 0;
93   {
94     volatile long double x = 1.0;
95     volatile long double y = ldexpl (x, -1);
96     if (y != 0.5L)
97       result |= 1;
98   }
99   {
100     volatile long double x = 1.73205L;
101     volatile long double y = ldexpl (x, 0);
102     if (y != x)
103       result |= 2;
104   }
105   return result;
106 }]])],
107         [gl_cv_func_ldexpl_works=yes],
108         [gl_cv_func_ldexpl_works=no],
109         [
110 changequote(,)dnl
111          case "$host_os" in
112            aix | aix[3-6]*) gl_cv_func_ldexpl_works="guessing no";;
113            *)               gl_cv_func_ldexpl_works="guessing yes";;
114          esac
115 changequote([,])dnl
116         ])
117     ])
118 ])