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