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