Complete last ChangeLog entry.
[gnulib.git] / m4 / ldexpl.m4
1 # ldexpl.m4 serial 7
2 dnl Copyright (C) 2007-2010 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   dnl Check whether it's declared.
11   dnl MacOS X 10.3 has ldexpl() in libc but doesn't declare it in <math.h>.
12   AC_CHECK_DECL([ldexpl], , [HAVE_DECL_LDEXPL=0], [#include <math.h>])
13   LDEXPL_LIBM=
14   if test $HAVE_DECL_LDEXPL = 1; then
15     gl_CHECK_LDEXPL_NO_LIBM
16     if test $gl_cv_func_ldexpl_no_libm = no; then
17       AC_CACHE_CHECK([whether ldexpl() can be used with libm],
18         [gl_cv_func_ldexpl_in_libm],
19         [
20           save_LIBS="$LIBS"
21           LIBS="$LIBS -lm"
22           AC_TRY_LINK([#include <math.h>
23                        long double x;],
24                       [return ldexpl (x, -1) > 0;],
25             [gl_cv_func_ldexpl_in_libm=yes],
26             [gl_cv_func_ldexpl_in_libm=no])
27           LIBS="$save_LIBS"
28         ])
29       if test $gl_cv_func_ldexpl_in_libm = yes; then
30         LDEXPL_LIBM=-lm
31       fi
32     fi
33     if test $gl_cv_func_ldexpl_no_libm = yes \
34        || test $gl_cv_func_ldexpl_in_libm = yes; then
35       save_LIBS="$LIBS"
36       LIBS="$LIBS $LDEXPL_LIBM"
37       gl_FUNC_LDEXPL_WORKS
38       LIBS="$save_LIBS"
39       case "$gl_cv_func_ldexpl_works" in
40         *yes) gl_func_ldexpl=yes ;;
41         *)    gl_func_ldexpl=no; REPLACE_LDEXPL=1; LDEXPL_LIBM= ;;
42       esac
43     else
44       gl_func_ldexpl=no
45     fi
46     if test $gl_func_ldexpl = yes; then
47       AC_DEFINE([HAVE_LDEXPL], [1],
48         [Define if the ldexpl() function is available.])
49     fi
50   fi
51   if test $HAVE_DECL_LDEXPL = 0 || test $gl_func_ldexpl = no; then
52     AC_LIBOBJ([ldexpl])
53   fi
54   AC_SUBST([LDEXPL_LIBM])
55 ])
56
57 dnl Test whether ldexpl() can be used without linking with libm.
58 dnl Set gl_cv_func_ldexpl_no_libm to 'yes' or 'no' accordingly.
59 AC_DEFUN([gl_CHECK_LDEXPL_NO_LIBM],
60 [
61   AC_CACHE_CHECK([whether ldexpl() can be used without linking with libm],
62     [gl_cv_func_ldexpl_no_libm],
63     [
64       AC_TRY_LINK([#include <math.h>
65                    long double x;],
66                   [return ldexpl (x, -1) > 0;],
67         [gl_cv_func_ldexpl_no_libm=yes],
68         [gl_cv_func_ldexpl_no_libm=no])
69     ])
70 ])
71
72 dnl Test whether ldexpl() works on finite numbers (this fails on AIX 5.1
73 dnl and MacOS X 10.4/PowerPC).
74 AC_DEFUN([gl_FUNC_LDEXPL_WORKS],
75 [
76   AC_REQUIRE([AC_PROG_CC])
77   AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
78   AC_CACHE_CHECK([whether ldexpl works], [gl_cv_func_ldexpl_works],
79     [
80       AC_TRY_RUN([
81 #include <math.h>
82 extern long double ldexpl (long double, int);
83 int main()
84 {
85   volatile long double x1 = 1.0;
86   volatile long double y1 = ldexpl (x1, -1);
87   volatile long double x2 = 1.73205L;
88   volatile long double y2 = ldexpl (x2, 0);
89   return (y1 != 0.5L) || (y2 != x2);
90 }], [gl_cv_func_ldexpl_works=yes], [gl_cv_func_ldexpl_works=no],
91       [
92 changequote(,)dnl
93        case "$host_os" in
94          aix | aix[3-6]*) gl_cv_func_ldexpl_works="guessing no";;
95          *)               gl_cv_func_ldexpl_works="guessing yes";;
96        esac
97 changequote([,])dnl
98       ])
99     ])
100 ])