maint: update copyright
[gnulib.git] / m4 / exp2.m4
1 # exp2.m4 serial 1
2 dnl Copyright (C) 2010-2014 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_EXP2],
8 [
9   AC_REQUIRE([gl_MATH_H_DEFAULTS])
10
11   dnl Persuade glibc <math.h> to declare exp2().
12   AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
13
14   EXP2_LIBM=
15   AC_CACHE_CHECK([whether exp2() can be used without linking with libm],
16     [gl_cv_func_exp2_no_libm],
17     [
18       AC_LINK_IFELSE(
19         [AC_LANG_PROGRAM(
20            [[#ifndef __NO_MATH_INLINES
21              # define __NO_MATH_INLINES 1 /* for glibc */
22              #endif
23              #include <math.h>
24              extern
25              #ifdef __cplusplus
26              "C"
27              #endif
28              double exp2 (double);
29              double (*funcptr) (double) = exp2;
30              double x;]],
31            [[return funcptr (x) > 1.5
32                     || exp2 (x) > 1.5;]])],
33         [gl_cv_func_exp2_no_libm=yes],
34         [gl_cv_func_exp2_no_libm=no])
35     ])
36   if test $gl_cv_func_exp2_no_libm = no; then
37     AC_CACHE_CHECK([whether exp2() can be used with libm],
38       [gl_cv_func_exp2_in_libm],
39       [
40         save_LIBS="$LIBS"
41         LIBS="$LIBS -lm"
42         AC_LINK_IFELSE(
43           [AC_LANG_PROGRAM(
44              [[#ifndef __NO_MATH_INLINES
45                # define __NO_MATH_INLINES 1 /* for glibc */
46                #endif
47                #include <math.h>
48                extern
49                #ifdef __cplusplus
50                "C"
51                #endif
52                double exp2 (double);
53                double (*funcptr) (double) = exp2;
54                double x;]],
55              [[return funcptr (x) > 1.5
56                       || exp2 (x) > 1.5;]])],
57           [gl_cv_func_exp2_in_libm=yes],
58           [gl_cv_func_exp2_in_libm=no])
59         LIBS="$save_LIBS"
60       ])
61     if test $gl_cv_func_exp2_in_libm = yes; then
62       EXP2_LIBM=-lm
63     fi
64   fi
65   if test $gl_cv_func_exp2_no_libm = yes \
66      || test $gl_cv_func_exp2_in_libm = yes; then
67     HAVE_EXP2=1
68     dnl Also check whether it's declared.
69     dnl IRIX 6.5 has exp2() in libm but doesn't declare it in <math.h>.
70     AC_CHECK_DECL([exp2], , [HAVE_DECL_EXP2=0], [[#include <math.h>]])
71     save_LIBS="$LIBS"
72     LIBS="$LIBS $EXP2_LIBM"
73     gl_FUNC_EXP2_WORKS
74     LIBS="$save_LIBS"
75     case "$gl_cv_func_exp2_works" in
76       *yes) ;;
77       *) REPLACE_EXP2=1 ;;
78     esac
79   else
80     HAVE_EXP2=0
81     HAVE_DECL_EXP2=0
82   fi
83   if test $HAVE_EXP2 = 0 || test $REPLACE_EXP2 = 1; then
84     dnl Find libraries needed to link lib/exp2.c.
85     AC_REQUIRE([gl_FUNC_ISNAND])
86     AC_REQUIRE([gl_FUNC_ROUND])
87     AC_REQUIRE([gl_FUNC_LDEXP])
88     EXP2_LIBM=
89     dnl Append $ISNAND_LIBM to EXP2_LIBM, avoiding gratuitous duplicates.
90     case " $EXP2_LIBM " in
91       *" $ISNAND_LIBM "*) ;;
92       *) EXP2_LIBM="$EXP2_LIBM $ISNAND_LIBM" ;;
93     esac
94     dnl Append $ROUND_LIBM to EXP2_LIBM, avoiding gratuitous duplicates.
95     case " $EXP2_LIBM " in
96       *" $ROUND_LIBM "*) ;;
97       *) EXP2_LIBM="$EXP2_LIBM $ROUND_LIBM" ;;
98     esac
99     dnl Append $LDEXP_LIBM to EXP2_LIBM, avoiding gratuitous duplicates.
100     case " $EXP2_LIBM " in
101       *" $LDEXP_LIBM "*) ;;
102       *) EXP2_LIBM="$EXP2_LIBM $LDEXP_LIBM" ;;
103     esac
104   fi
105   AC_SUBST([EXP2_LIBM])
106 ])
107
108 dnl Test whether exp2() works.
109 dnl On OpenBSD 4.9, for the argument 0.6, it returns 1.517358639986284397,
110 dnl which has a relative error of 0.1%.
111 AC_DEFUN([gl_FUNC_EXP2_WORKS],
112 [
113   AC_REQUIRE([AC_PROG_CC])
114   AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
115   AC_CACHE_CHECK([whether exp2 works], [gl_cv_func_exp2_works],
116     [
117       AC_RUN_IFELSE(
118         [AC_LANG_SOURCE([[
119 #include <math.h>
120 extern
121 #ifdef __cplusplus
122 "C"
123 #endif
124 double exp2 (double);
125 volatile double x;
126 double y;
127 int main ()
128 {
129   x = 0.6;
130   y = exp2 (x);
131   if (y > 1.516)
132     return 1;
133   return 0;
134 }
135 ]])],
136         [gl_cv_func_exp2_works=yes],
137         [gl_cv_func_exp2_works=no],
138         [case "$host_os" in
139            openbsd*) gl_cv_func_exp2_works="guessing no";;
140            *)        gl_cv_func_exp2_works="guessing yes";;
141          esac
142         ])
143     ])
144 ])