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().
20 LIBS="$LIBS $EXP2_LIBM"
21 AC_CHECK_FUNCS([exp2l])
23 if test $ac_cv_func_exp2l = yes; then
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],
35 LIBS="$LIBS $EXP2L_LIBM"
38 #ifndef __NO_MATH_INLINES
39 # define __NO_MATH_INLINES 1 /* for glibc */
43 /* Override the values of <float.h>, like done in float.in.h. */
44 #if defined __i386__ && (defined __BEOS__ || defined __OpenBSD__)
46 # define LDBL_MANT_DIG 64
48 # define LDBL_MIN_EXP (-16381)
50 # define LDBL_MAX_EXP 16384
52 #if defined __i386__ && (defined __FreeBSD__ || defined __DragonFly__)
54 # define LDBL_MANT_DIG 64
56 # define LDBL_MIN_EXP (-16381)
58 # define LDBL_MAX_EXP 16384
60 #if (defined _ARCH_PPC || defined _POWER) && defined _AIX && (LDBL_MANT_DIG == 106) && defined __GNUC__
62 # define LDBL_MIN_EXP DBL_MIN_EXP
64 #if defined __sgi && (LDBL_MANT_DIG >= 106)
66 # define LDBL_MANT_DIG 106
69 # define LDBL_MIN_EXP DBL_MIN_EXP
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;
83 /* This test fails on NetBSD 9.0. */
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))
99 [gl_cv_func_exp2l_works=yes],
100 [gl_cv_func_exp2l_works=no],
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" ;;
114 case "$gl_cv_func_exp2l_works" in
116 *) REPLACE_EXP2L=1 ;;
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],
126 LIBS="$LIBS $EXP2L_LIBM"
129 #ifndef __NO_MATH_INLINES
130 # define __NO_MATH_INLINES 1 /* for glibc */
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;
145 /* This test fails on OpenBSD 4.9, where exp2l(NaN) = 0.0. */
146 if (exp2l (zero / zero) == 0.0L)
148 /* This test fails on IRIX 6.5, where exp2l(-Inf) = 1.0. */
149 if (!(exp2l (-1.0L / zero) == 0.0L))
154 [gl_cv_func_exp2l_ieee=yes],
155 [gl_cv_func_exp2l_ieee=no],
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" ;;
169 case "$gl_cv_func_exp2l_ieee" in
171 *) REPLACE_EXP2L=1 ;;
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"
184 AC_REQUIRE([gl_FUNC_ISNANL])
185 AC_REQUIRE([gl_FUNC_ROUNDL])
186 AC_REQUIRE([gl_FUNC_LDEXPL])
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" ;;
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" ;;
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" ;;
205 AC_SUBST([EXP2L_LIBM])