immutable: Add tests.
[gnulib.git] / m4 / exp2l.m4
blob3ab9b11815f938a9fbdc23d3aea4a4e926b5dbb1
1 # exp2l.m4 serial 10
2 dnl Copyright (C) 2010-2021 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     if test $REPLACE_EXP2L = 0; then
30       AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
31       AC_CACHE_CHECK([whether exp2l works],
32         [gl_cv_func_exp2l_works],
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 <float.h>
42 #include <math.h>
43 /* Override the values of <float.h>, like done in float.in.h.  */
44 #if defined __i386__ && (defined __BEOS__ || defined __OpenBSD__)
45 # undef LDBL_MANT_DIG
46 # define LDBL_MANT_DIG   64
47 # undef LDBL_MIN_EXP
48 # define LDBL_MIN_EXP    (-16381)
49 # undef LDBL_MAX_EXP
50 # define LDBL_MAX_EXP    16384
51 #endif
52 #if defined __i386__ && (defined __FreeBSD__ || defined __DragonFly__)
53 # undef LDBL_MANT_DIG
54 # define LDBL_MANT_DIG   64
55 # undef LDBL_MIN_EXP
56 # define LDBL_MIN_EXP    (-16381)
57 # undef LDBL_MAX_EXP
58 # define LDBL_MAX_EXP    16384
59 #endif
60 #if (defined _ARCH_PPC || defined _POWER) && defined _AIX && (LDBL_MANT_DIG == 106) && defined __GNUC__
61 # undef LDBL_MIN_EXP
62 # define LDBL_MIN_EXP DBL_MIN_EXP
63 #endif
64 #if defined __sgi && (LDBL_MANT_DIG >= 106)
65 # undef LDBL_MANT_DIG
66 # define LDBL_MANT_DIG 106
67 # if defined __GNUC__
68 #  undef LDBL_MIN_EXP
69 #  define LDBL_MIN_EXP DBL_MIN_EXP
70 # endif
71 #endif
72 #undef exp2l
73 extern
74 #ifdef __cplusplus
75 "C"
76 #endif
77 long double exp2l (long double);
78 static long double dummy (long double x) { return 0; }
79 int main (int argc, char *argv[])
81   long double (* volatile my_exp2l) (long double) = argc ? exp2l : dummy;
82   int result = 0;
83   /* This test fails on NetBSD 9.0.  */
84   {
85     const long double TWO_LDBL_MANT_DIG = /* 2^LDBL_MANT_DIG */
86       (long double) (1U << ((LDBL_MANT_DIG - 1) / 5))
87       * (long double) (1U << ((LDBL_MANT_DIG - 1 + 1) / 5))
88       * (long double) (1U << ((LDBL_MANT_DIG - 1 + 2) / 5))
89       * (long double) (1U << ((LDBL_MANT_DIG - 1 + 3) / 5))
90       * (long double) (1U << ((LDBL_MANT_DIG - 1 + 4) / 5));
91     long double x = 11.358L;
92     long double err = (my_exp2l (x) * my_exp2l (- x) - 1.0L) * TWO_LDBL_MANT_DIG;
93     if (!(err >= -100.0L && err <= 100.0L))
94       result |= 1;
95   }
96   return result;
98             ]])],
99             [gl_cv_func_exp2l_works=yes],
100             [gl_cv_func_exp2l_works=no],
101             [case "$host_os" in
102                               # Guess yes on glibc systems.
103                *-gnu* | gnu*) gl_cv_func_exp2l_works="guessing yes" ;;
104                               # Guess yes on musl systems.
105                *-musl*)       gl_cv_func_exp2l_works="guessing yes" ;;
106                               # Guess yes on native Windows.
107                mingw*)        gl_cv_func_exp2l_works="guessing yes" ;;
108                               # If we don't know, obey --enable-cross-guesses.
109                *)             gl_cv_func_exp2l_works="$gl_cross_guess_normal" ;;
110              esac
111             ])
112           LIBS="$save_LIBS"
113         ])
114       case "$gl_cv_func_exp2l_works" in
115         *yes) ;;
116         *) REPLACE_EXP2L=1 ;;
117       esac
118     fi
119     m4_ifdef([gl_FUNC_EXP2L_IEEE], [
120       if test $gl_exp2l_required = ieee && test $REPLACE_EXP2L = 0; then
121         AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
122         AC_CACHE_CHECK([whether exp2l works according to ISO C 99 with IEC 60559],
123           [gl_cv_func_exp2l_ieee],
124           [
125             save_LIBS="$LIBS"
126             LIBS="$LIBS $EXP2L_LIBM"
127             AC_RUN_IFELSE(
128               [AC_LANG_SOURCE([[
129 #ifndef __NO_MATH_INLINES
130 # define __NO_MATH_INLINES 1 /* for glibc */
131 #endif
132 #include <math.h>
133 #undef exp2l
134 extern
135 #ifdef __cplusplus
137 #endif
138 long double exp2l (long double);
139 static long double dummy (long double x) { return 0; }
140 static long double zero;
141 int main (int argc, char *argv[])
143   long double (* volatile my_exp2l) (long double) = argc ? exp2l : dummy;
144   int result = 0;
145   /* This test fails on OpenBSD 4.9, where exp2l(NaN) = 0.0.  */
146   if (exp2l (zero / zero) == 0.0L)
147     result |= 1;
148   /* This test fails on IRIX 6.5, where exp2l(-Inf) = 1.0.  */
149   if (!(exp2l (-1.0L / zero) == 0.0L))
150     result |= 2;
151   return result;
153               ]])],
154               [gl_cv_func_exp2l_ieee=yes],
155               [gl_cv_func_exp2l_ieee=no],
156               [case "$host_os" in
157                                 # Guess yes on glibc systems.
158                  *-gnu* | gnu*) gl_cv_func_exp2l_ieee="guessing yes" ;;
159                                 # Guess yes on musl systems.
160                  *-musl*)       gl_cv_func_exp2l_ieee="guessing yes" ;;
161                                 # Guess yes on native Windows.
162                  mingw*)        gl_cv_func_exp2l_ieee="guessing yes" ;;
163                                 # If we don't know, obey --enable-cross-guesses.
164                  *)             gl_cv_func_exp2l_ieee="$gl_cross_guess_normal" ;;
165                esac
166               ])
167             LIBS="$save_LIBS"
168           ])
169         case "$gl_cv_func_exp2l_ieee" in
170           *yes) ;;
171           *) REPLACE_EXP2L=1 ;;
172         esac
173       fi
174     ])
175   else
176     HAVE_EXP2L=0
177     HAVE_DECL_EXP2L=0
178   fi
179   if test $HAVE_EXP2L = 0 || test $REPLACE_EXP2L = 1; then
180     dnl Find libraries needed to link lib/exp2l.c.
181     if test $HAVE_SAME_LONG_DOUBLE_AS_DOUBLE = 1; then
182       EXP2L_LIBM="$EXP2_LIBM"
183     else
184       AC_REQUIRE([gl_FUNC_ISNANL])
185       AC_REQUIRE([gl_FUNC_ROUNDL])
186       AC_REQUIRE([gl_FUNC_LDEXPL])
187       EXP2L_LIBM=
188       dnl Append $ISNANL_LIBM to EXP2L_LIBM, avoiding gratuitous duplicates.
189       case " $EXP2L_LIBM " in
190         *" $ISNANL_LIBM "*) ;;
191         *) EXP2L_LIBM="$EXP2L_LIBM $ISNANL_LIBM" ;;
192       esac
193       dnl Append $ROUNDL_LIBM to EXP2L_LIBM, avoiding gratuitous duplicates.
194       case " $EXP2L_LIBM " in
195         *" $ROUNDL_LIBM "*) ;;
196         *) EXP2L_LIBM="$EXP2L_LIBM $ROUNDL_LIBM" ;;
197       esac
198       dnl Append $LDEXPL_LIBM to EXP2L_LIBM, avoiding gratuitous duplicates.
199       case " $EXP2L_LIBM " in
200         *" $LDEXPL_LIBM "*) ;;
201         *) EXP2L_LIBM="$EXP2L_LIBM $LDEXPL_LIBM" ;;
202       esac
203     fi
204   fi
205   AC_SUBST([EXP2L_LIBM])