Imported Upstream version 1.3.14
[debian/gzip] / m4 / ldexpl.m4
1 # ldexpl.m4 serial 4
2 dnl Copyright (C) 2007-2009 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   LDEXPL_LIBM=
11   AC_CACHE_CHECK([whether ldexpl() can be used without linking with libm],
12     [gl_cv_func_ldexpl_no_libm],
13     [
14       AC_TRY_LINK([#include <math.h>
15                    long double x;],
16                   [return ldexpl (x, -1) > 0;],
17         [gl_cv_func_ldexpl_no_libm=yes],
18         [gl_cv_func_ldexpl_no_libm=no])
19     ])
20   if test $gl_cv_func_ldexpl_no_libm = no; then
21     AC_CACHE_CHECK([whether ldexpl() can be used with libm],
22       [gl_cv_func_ldexpl_in_libm],
23       [
24         save_LIBS="$LIBS"
25         LIBS="$LIBS -lm"
26         AC_TRY_LINK([#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; LDEXPL_LIBM= ;;
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     dnl Also check whether it's declared.
54     dnl MacOS X 10.3 has ldexpl() in libc but doesn't declare it in <math.h>.
55     AC_CHECK_DECL([ldexpl], , [HAVE_DECL_LDEXPL=0], [#include <math.h>])
56   else
57     HAVE_DECL_LDEXPL=0
58     AC_LIBOBJ([ldexpl])
59   fi
60   AC_SUBST([LDEXPL_LIBM])
61 ])
62
63 dnl Test whether ldexpl() works on finite numbers (this fails on AIX 5.1
64 dnl and MacOS X 10.4/PowerPC).
65 AC_DEFUN([gl_FUNC_LDEXPL_WORKS],
66 [
67   AC_REQUIRE([AC_PROG_CC])
68   AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
69   AC_CACHE_CHECK([whether ldexpl works], [gl_cv_func_ldexpl_works],
70     [
71       AC_TRY_RUN([
72 #include <math.h>
73 extern long double ldexpl (long double, int);
74 int main()
75 {
76   volatile long double x1 = 1.0;
77   volatile long double y1 = ldexpl (x1, -1);
78   volatile long double x2 = 1.73205L;
79   volatile long double y2 = ldexpl (x2, 0);
80   return (y1 != 0.5L) || (y2 != x2);
81 }], [gl_cv_func_ldexpl_works=yes], [gl_cv_func_ldexpl_works=no],
82       [case "$host_os" in
83          aix*) gl_cv_func_ldexpl_works="guessing no";;
84          *)    gl_cv_func_ldexpl_works="guessing yes";;
85        esac
86       ])
87     ])
88 ])