strtod, strtold: Use the locale's decimal point.
[gnulib.git] / m4 / exp2l.m4
blob8a065d9048d4ef0bd93546cb0c09c60710333822
1 # exp2l.m4 serial 7
2 dnl Copyright (C) 2010-2019 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 8.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 native Windows.
105                mingw*)        gl_cv_func_exp2l_works="guessing yes" ;;
106                               # If we don't know, assume the worst.
107                *)             gl_cv_func_exp2l_works="guessing no" ;;
108              esac
109             ])
110           LIBS="$save_LIBS"
111         ])
112       case "$gl_cv_func_exp2l_works" in
113         *yes) ;;
114         *) REPLACE_EXP2L=1 ;;
115       esac
116     fi
117     m4_ifdef([gl_FUNC_EXP2L_IEEE], [
118       if test $gl_exp2l_required = ieee && test $REPLACE_EXP2L = 0; then
119         AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
120         AC_CACHE_CHECK([whether exp2l works according to ISO C 99 with IEC 60559],
121           [gl_cv_func_exp2l_ieee],
122           [
123             save_LIBS="$LIBS"
124             LIBS="$LIBS $EXP2L_LIBM"
125             AC_RUN_IFELSE(
126               [AC_LANG_SOURCE([[
127 #ifndef __NO_MATH_INLINES
128 # define __NO_MATH_INLINES 1 /* for glibc */
129 #endif
130 #include <math.h>
131 #undef exp2l
132 extern
133 #ifdef __cplusplus
135 #endif
136 long double exp2l (long double);
137 static long double dummy (long double x) { return 0; }
138 static long double zero;
139 int main (int argc, char *argv[])
141   long double (* volatile my_exp2l) (long double) = argc ? exp2l : dummy;
142   int result = 0;
143   /* This test fails on OpenBSD 4.9, where exp2l(NaN) = 0.0.  */
144   if (exp2l (zero / zero) == 0.0L)
145     result |= 1;
146   /* This test fails on IRIX 6.5, where exp2l(-Inf) = 1.0.  */
147   if (!(exp2l (-1.0L / zero) == 0.0L))
148     result |= 2;
149   return result;
151               ]])],
152               [gl_cv_func_exp2l_ieee=yes],
153               [gl_cv_func_exp2l_ieee=no],
154               [case "$host_os" in
155                                 # Guess yes on glibc systems.
156                  *-gnu* | gnu*) gl_cv_func_exp2l_ieee="guessing yes" ;;
157                                 # Guess yes on native Windows.
158                  mingw*)        gl_cv_func_exp2l_ieee="guessing yes" ;;
159                                 # If we don't know, assume the worst.
160                  *)             gl_cv_func_exp2l_ieee="guessing no" ;;
161                esac
162               ])
163             LIBS="$save_LIBS"
164           ])
165         case "$gl_cv_func_exp2l_ieee" in
166           *yes) ;;
167           *) REPLACE_EXP2L=1 ;;
168         esac
169       fi
170     ])
171   else
172     HAVE_EXP2L=0
173     HAVE_DECL_EXP2L=0
174   fi
175   if test $HAVE_EXP2L = 0 || test $REPLACE_EXP2L = 1; then
176     dnl Find libraries needed to link lib/exp2l.c.
177     if test $HAVE_SAME_LONG_DOUBLE_AS_DOUBLE = 1; then
178       EXP2L_LIBM="$EXP2_LIBM"
179     else
180       AC_REQUIRE([gl_FUNC_ISNANL])
181       AC_REQUIRE([gl_FUNC_ROUNDL])
182       AC_REQUIRE([gl_FUNC_LDEXPL])
183       EXP2L_LIBM=
184       dnl Append $ISNANL_LIBM to EXP2L_LIBM, avoiding gratuitous duplicates.
185       case " $EXP2L_LIBM " in
186         *" $ISNANL_LIBM "*) ;;
187         *) EXP2L_LIBM="$EXP2L_LIBM $ISNANL_LIBM" ;;
188       esac
189       dnl Append $ROUNDL_LIBM to EXP2L_LIBM, avoiding gratuitous duplicates.
190       case " $EXP2L_LIBM " in
191         *" $ROUNDL_LIBM "*) ;;
192         *) EXP2L_LIBM="$EXP2L_LIBM $ROUNDL_LIBM" ;;
193       esac
194       dnl Append $LDEXPL_LIBM to EXP2L_LIBM, avoiding gratuitous duplicates.
195       case " $EXP2L_LIBM " in
196         *" $LDEXPL_LIBM "*) ;;
197         *) EXP2L_LIBM="$EXP2L_LIBM $LDEXPL_LIBM" ;;
198       esac
199     fi
200   fi
201   AC_SUBST([EXP2L_LIBM])