Put more information about failed tests into the test return codes.
[gnulib.git] / m4 / ldexpl.m4
1 # ldexpl.m4 serial 9
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_LINK_IFELSE(
23             [AC_LANG_PROGRAM(
24                [[#include <math.h>
25                  long double x;]],
26                [[return ldexpl (x, -1) > 0;]])],
27             [gl_cv_func_ldexpl_in_libm=yes],
28             [gl_cv_func_ldexpl_in_libm=no])
29           LIBS="$save_LIBS"
30         ])
31       if test $gl_cv_func_ldexpl_in_libm = yes; then
32         LDEXPL_LIBM=-lm
33       fi
34     fi
35     if test $gl_cv_func_ldexpl_no_libm = yes \
36        || test $gl_cv_func_ldexpl_in_libm = yes; then
37       save_LIBS="$LIBS"
38       LIBS="$LIBS $LDEXPL_LIBM"
39       gl_FUNC_LDEXPL_WORKS
40       LIBS="$save_LIBS"
41       case "$gl_cv_func_ldexpl_works" in
42         *yes) gl_func_ldexpl=yes ;;
43         *)    gl_func_ldexpl=no; REPLACE_LDEXPL=1; LDEXPL_LIBM= ;;
44       esac
45     else
46       gl_func_ldexpl=no
47     fi
48     if test $gl_func_ldexpl = yes; then
49       AC_DEFINE([HAVE_LDEXPL], [1],
50         [Define if the ldexpl() function is available.])
51     fi
52   fi
53   if test $HAVE_DECL_LDEXPL = 0 || test $gl_func_ldexpl = no; then
54     AC_LIBOBJ([ldexpl])
55   fi
56   AC_SUBST([LDEXPL_LIBM])
57 ])
58
59 dnl Test whether ldexpl() can be used without linking with libm.
60 dnl Set gl_cv_func_ldexpl_no_libm to 'yes' or 'no' accordingly.
61 AC_DEFUN([gl_CHECK_LDEXPL_NO_LIBM],
62 [
63   AC_CACHE_CHECK([whether ldexpl() can be used without linking with libm],
64     [gl_cv_func_ldexpl_no_libm],
65     [
66       AC_LINK_IFELSE(
67         [AC_LANG_PROGRAM(
68            [[#include <math.h>
69              long double x;]],
70            [[return ldexpl (x, -1) > 0;]])],
71         [gl_cv_func_ldexpl_no_libm=yes],
72         [gl_cv_func_ldexpl_no_libm=no])
73     ])
74 ])
75
76 dnl Test whether ldexpl() works on finite numbers (this fails on AIX 5.1
77 dnl and MacOS X 10.4/PowerPC).
78 AC_DEFUN([gl_FUNC_LDEXPL_WORKS],
79 [
80   AC_REQUIRE([AC_PROG_CC])
81   AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
82   AC_CACHE_CHECK([whether ldexpl works], [gl_cv_func_ldexpl_works],
83     [
84       AC_RUN_IFELSE(
85         [AC_LANG_SOURCE([[
86 #include <math.h>
87 extern long double ldexpl (long double, int);
88 int main()
89 {
90   int result = 0;
91   {
92     volatile long double x = 1.0;
93     volatile long double y = ldexpl (x, -1);
94     if (y != 0.5L)
95       result |= 1;
96   }
97   {
98     volatile long double x = 1.73205L;
99     volatile long double y = ldexpl (x, 0);
100     if (y != x)
101       result |= 2;
102   }
103   return result;
104 }]])],
105         [gl_cv_func_ldexpl_works=yes],
106         [gl_cv_func_ldexpl_works=no],
107         [
108 changequote(,)dnl
109          case "$host_os" in
110            aix | aix[3-6]*) gl_cv_func_ldexpl_works="guessing no";;
111            *)               gl_cv_func_ldexpl_works="guessing yes";;
112          esac
113 changequote([,])dnl
114         ])
115     ])
116 ])