605cd14c76ca03241f315433240504176642f1be
[gnulib.git] / m4 / exp2l.m4
1 # exp2l.m4 serial 2
2 dnl Copyright (C) 2010-2012 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_EXP2L],
8 [
9   m4_divert_text([DEFAULTS], [gl_exp2l_required=plain])
10   AC_REQUIRE([gl_MATH_H_DEFAULTS])
11   AC_REQUIRE([gl_LONG_DOUBLE_VS_DOUBLE])
12   AC_REQUIRE([gl_FUNC_EXP2])
13
14   dnl Persuade glibc <math.h> to declare exp2l().
15   AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
16
17   dnl Test whether exp2l() exists. Assume that exp2l(), if it exists, is
18   dnl defined in the same library as exp2().
19   save_LIBS="$LIBS"
20   LIBS="$LIBS $EXP2_LIBM"
21   AC_CHECK_FUNCS([exp2l])
22   LIBS="$save_LIBS"
23   if test $ac_cv_func_exp2l = yes; then
24     HAVE_EXP2L=1
25     EXP2L_LIBM="$EXP2_LIBM"
26     dnl Also check whether it's declared.
27     dnl IRIX 6.5 has exp2l() in libm but doesn't declare it in <math.h>.
28     AC_CHECK_DECL([exp2l], , [HAVE_DECL_EXP2L=0], [[#include <math.h>]])
29     m4_ifdef([gl_FUNC_EXP2L_IEEE], [
30       if test $gl_exp2l_required = ieee && test $REPLACE_EXP2L = 0; then
31         AC_CACHE_CHECK([whether exp2l works according to ISO C 99 with IEC 60559],
32           [gl_cv_func_exp2l_ieee],
33           [
34             save_LIBS="$LIBS"
35             LIBS="$LIBS $EXP2L_LIBM"
36             AC_RUN_IFELSE(
37               [AC_LANG_SOURCE([[
38 #ifndef __NO_MATH_INLINES
39 # define __NO_MATH_INLINES 1 /* for glibc */
40 #endif
41 #include <math.h>
42 #undef exp2l
43 extern
44 #ifdef __cplusplus
45 "C"
46 #endif
47 long double exp2l (long double);
48 static long double dummy (long double x) { return 0; }
49 static long double zero;
50 int main (int argc, char *argv[])
51 {
52   long double (*my_exp2l) (long double) = argc ? exp2l : dummy;
53   int result = 0;
54   /* This test fails on OpenBSD 4.9, where exp2l(NaN) = 0.0.  */
55   if (exp2l (zero / zero) == 0.0L)
56     result |= 1;
57   /* This test fails on IRIX 6.5, where exp2l(-Inf) = 1.0.  */
58   if (!(exp2l (-1.0L / zero) == 0.0L))
59     result |= 2;
60   return result;
61 }
62               ]])],
63               [gl_cv_func_exp2l_ieee=yes],
64               [gl_cv_func_exp2l_ieee=no],
65               [gl_cv_func_exp2l_ieee="guessing no"])
66             LIBS="$save_LIBS"
67           ])
68         case "$gl_cv_func_exp2l_ieee" in
69           *yes) ;;
70           *) REPLACE_EXP2L=1 ;;
71         esac
72       fi
73     ])
74   else
75     HAVE_EXP2L=0
76     HAVE_DECL_EXP2L=0
77   fi
78   if test $HAVE_EXP2L = 0 || test $REPLACE_EXP2L = 1; then
79     dnl Find libraries needed to link lib/exp2l.c.
80     if test $HAVE_SAME_LONG_DOUBLE_AS_DOUBLE = 1; then
81       EXP2L_LIBM="$EXP2_LIBM"
82     else
83       AC_REQUIRE([gl_FUNC_ISNANL])
84       AC_REQUIRE([gl_FUNC_ROUNDL])
85       AC_REQUIRE([gl_FUNC_LDEXPL])
86       EXP2L_LIBM=
87       dnl Append $ISNANL_LIBM to EXP2L_LIBM, avoiding gratuitous duplicates.
88       case " $EXP2L_LIBM " in
89         *" $ISNANL_LIBM "*) ;;
90         *) EXP2L_LIBM="$EXP2L_LIBM $ISNANL_LIBM" ;;
91       esac
92       dnl Append $ROUNDL_LIBM to EXP2L_LIBM, avoiding gratuitous duplicates.
93       case " $EXP2L_LIBM " in
94         *" $ROUNDL_LIBM "*) ;;
95         *) EXP2L_LIBM="$EXP2L_LIBM $ROUNDL_LIBM" ;;
96       esac
97       dnl Append $LDEXPL_LIBM to EXP2L_LIBM, avoiding gratuitous duplicates.
98       case " $EXP2L_LIBM " in
99         *" $LDEXPL_LIBM "*) ;;
100         *) EXP2L_LIBM="$EXP2L_LIBM $LDEXPL_LIBM" ;;
101       esac
102     fi
103   fi
104   AC_SUBST([EXP2L_LIBM])
105 ])