localename: Fine-tune support for per-thread locales on Solaris 11.4.
[gnulib.git] / m4 / exp2l.m4
blobe8ffcbb054ea9abd1b8ca01632509d0b041e2ae8
1 # exp2l.m4 serial 5
2 dnl Copyright (C) 2010-2018 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.
7 AC_DEFUN([gl_FUNC_EXP2L],
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])
14   dnl Persuade glibc <math.h> to declare exp2l().
15   AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
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_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
32         AC_CACHE_CHECK([whether exp2l works according to ISO C 99 with IEC 60559],
33           [gl_cv_func_exp2l_ieee],
34           [
35             save_LIBS="$LIBS"
36             LIBS="$LIBS $EXP2L_LIBM"
37             AC_RUN_IFELSE(
38               [AC_LANG_SOURCE([[
39 #ifndef __NO_MATH_INLINES
40 # define __NO_MATH_INLINES 1 /* for glibc */
41 #endif
42 #include <math.h>
43 #undef exp2l
44 extern
45 #ifdef __cplusplus
46 "C"
47 #endif
48 long double exp2l (long double);
49 static long double dummy (long double x) { return 0; }
50 static long double zero;
51 int main (int argc, char *argv[])
53   long double (*my_exp2l) (long double) = argc ? exp2l : dummy;
54   int result = 0;
55   /* This test fails on OpenBSD 4.9, where exp2l(NaN) = 0.0.  */
56   if (exp2l (zero / zero) == 0.0L)
57     result |= 1;
58   /* This test fails on IRIX 6.5, where exp2l(-Inf) = 1.0.  */
59   if (!(exp2l (-1.0L / zero) == 0.0L))
60     result |= 2;
61   return result;
63               ]])],
64               [gl_cv_func_exp2l_ieee=yes],
65               [gl_cv_func_exp2l_ieee=no],
66               [case "$host_os" in
67                                 # Guess yes on glibc systems.
68                  *-gnu* | gnu*) gl_cv_func_exp2l_ieee="guessing yes" ;;
69                                 # Guess yes on native Windows.
70                  mingw*)        gl_cv_func_exp2l_ieee="guessing yes" ;;
71                                 # If we don't know, assume the worst.
72                  *)             gl_cv_func_exp2l_ieee="guessing no" ;;
73                esac
74               ])
75             LIBS="$save_LIBS"
76           ])
77         case "$gl_cv_func_exp2l_ieee" in
78           *yes) ;;
79           *) REPLACE_EXP2L=1 ;;
80         esac
81       fi
82     ])
83   else
84     HAVE_EXP2L=0
85     HAVE_DECL_EXP2L=0
86   fi
87   if test $HAVE_EXP2L = 0 || test $REPLACE_EXP2L = 1; then
88     dnl Find libraries needed to link lib/exp2l.c.
89     if test $HAVE_SAME_LONG_DOUBLE_AS_DOUBLE = 1; then
90       EXP2L_LIBM="$EXP2_LIBM"
91     else
92       AC_REQUIRE([gl_FUNC_ISNANL])
93       AC_REQUIRE([gl_FUNC_ROUNDL])
94       AC_REQUIRE([gl_FUNC_LDEXPL])
95       EXP2L_LIBM=
96       dnl Append $ISNANL_LIBM to EXP2L_LIBM, avoiding gratuitous duplicates.
97       case " $EXP2L_LIBM " in
98         *" $ISNANL_LIBM "*) ;;
99         *) EXP2L_LIBM="$EXP2L_LIBM $ISNANL_LIBM" ;;
100       esac
101       dnl Append $ROUNDL_LIBM to EXP2L_LIBM, avoiding gratuitous duplicates.
102       case " $EXP2L_LIBM " in
103         *" $ROUNDL_LIBM "*) ;;
104         *) EXP2L_LIBM="$EXP2L_LIBM $ROUNDL_LIBM" ;;
105       esac
106       dnl Append $LDEXPL_LIBM to EXP2L_LIBM, avoiding gratuitous duplicates.
107       case " $EXP2L_LIBM " in
108         *" $LDEXPL_LIBM "*) ;;
109         *) EXP2L_LIBM="$EXP2L_LIBM $LDEXPL_LIBM" ;;
110       esac
111     fi
112   fi
113   AC_SUBST([EXP2L_LIBM])