Debian Codegraph @

m4/expl.m4

raw
1 # expl.m4
2 # serial 22
3 dnl Copyright (C) 2010-2025 Free Software Foundation, Inc.
4 dnl This file is free software; the Free Software Foundation
5 dnl gives unlimited permission to copy and/or distribute it,
6 dnl with or without modifications, as long as this notice is preserved.
7 dnl This file is offered as-is, without any warranty.
8
9 AC_DEFUN([gl_FUNC_EXPL],
10 [
11 AC_REQUIRE([gl_MATH_H_DEFAULTS])
12 AC_REQUIRE([gl_LONG_DOUBLE_VS_DOUBLE])
13 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
14
15 dnl Persuade glibc <math.h> to declare expl().
16 AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
17
18 EXPL_LIBM=
19 AC_CACHE_CHECK([whether expl() can be used without linking with libm],
20 [gl_cv_func_expl_no_libm],
21 [
22 AC_LINK_IFELSE(
23 [AC_LANG_PROGRAM(
24 [[#ifndef __NO_MATH_INLINES
25 # define __NO_MATH_INLINES 1 /* for glibc */
26 #endif
27 #include <math.h>
28 long double (* volatile funcptr) (long double) = expl;
29 long double x;]],
30 [[return funcptr (x) > 1.5
31 || expl (x) > 1.5;]])],
32 [gl_cv_func_expl_no_libm=yes],
33 [gl_cv_func_expl_no_libm=no])
34 ])
35 if test $gl_cv_func_expl_no_libm = no; then
36 AC_CACHE_CHECK([whether expl() can be used with libm],
37 [gl_cv_func_expl_in_libm],
38 [
39 saved_LIBS="$LIBS"
40 LIBS="$LIBS -lm"
41 AC_LINK_IFELSE(
42 [AC_LANG_PROGRAM(
43 [[#ifndef __NO_MATH_INLINES
44 # define __NO_MATH_INLINES 1 /* for glibc */
45 #endif
46 #include <math.h>
47 long double (* volatile funcptr) (long double) = expl;
48 long double x;]],
49 [[return funcptr (x) > 1.5
50 || expl (x) > 1.5;]])],
51 [gl_cv_func_expl_in_libm=yes],
52 [gl_cv_func_expl_in_libm=no])
53 LIBS="$saved_LIBS"
54 ])
55 if test $gl_cv_func_expl_in_libm = yes; then
56 EXPL_LIBM=-lm
57 fi
58 fi
59 if test $gl_cv_func_expl_no_libm = yes \
60 || test $gl_cv_func_expl_in_libm = yes; then
61 dnl Also check whether it's declared.
62 dnl Mac OS X 10.3 has expl() in libc but doesn't declare it in <math.h>.
63 AC_CHECK_DECL([expl], , [HAVE_DECL_EXPL=0], [[#include <math.h>]])
64 if test $REPLACE_EXPL = 0; then
65 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
66 AC_CACHE_CHECK([whether expl works],
67 [gl_cv_func_expl_works],
68 [
69 saved_LIBS="$LIBS"
70 LIBS="$LIBS $EXPL_LIBM"
71 AC_RUN_IFELSE(
72 [AC_LANG_SOURCE([[
73 #ifndef __NO_MATH_INLINES
74 # define __NO_MATH_INLINES 1 /* for glibc */
75 #endif
76 #include <float.h>
77 #include <math.h>
78 /* Override the values of <float.h>, like done in float.in.h. */
79 #if defined __i386__ && (defined __BEOS__ || defined __OpenBSD__)
80 # undef LDBL_MANT_DIG
81 # define LDBL_MANT_DIG 64
82 # undef LDBL_MIN_EXP
83 # define LDBL_MIN_EXP (-16381)
84 # undef LDBL_MAX_EXP
85 # define LDBL_MAX_EXP 16384
86 #endif
87 #if defined __i386__ && (defined __FreeBSD__ || defined __DragonFly__)
88 # undef LDBL_MANT_DIG
89 # define LDBL_MANT_DIG 64
90 # undef LDBL_MIN_EXP
91 # define LDBL_MIN_EXP (-16381)
92 # undef LDBL_MAX_EXP
93 # define LDBL_MAX_EXP 16384
94 #endif
95 #if (defined _ARCH_PPC || defined _POWER) && defined _AIX && (LDBL_MANT_DIG == 106) && defined __GNUC__
96 # undef LDBL_MIN_EXP
97 # define LDBL_MIN_EXP DBL_MIN_EXP
98 #endif
99 #if defined __sgi && (LDBL_MANT_DIG >= 106)
100 # undef LDBL_MANT_DIG
101 # define LDBL_MANT_DIG 106
102 # if defined __GNUC__
103 # undef LDBL_MIN_EXP
104 # define LDBL_MIN_EXP DBL_MIN_EXP
105 # endif
106 #endif
107 #undef expl
108 extern
109 #ifdef __cplusplus
110 "C"
111 #endif
112 long double expl (long double);
113 static long double dummy (long double x) { return 0; }
114 int main (int argc, char *argv[])
115 {
116 long double (* volatile my_expl) (long double) = argc ? expl : dummy;
117 int result = 0;
118 /* On Haiku 2017 the system's native expl() is just a stub: it returns 0.0
119 and prints "__expl not implemented" for all arguments. */
120 {
121 volatile long double x1 = -1.0;
122 if (expl (x1) == 0.0)
123 result |= 1;
124 }
125 /* On OpenBSD 5.4 the system's native expl() is buggy:
126 it returns 'nan' for small values. */
127 {
128 volatile long double x1 = -1.0;
129 volatile long double x2 = -0.8;
130 volatile long double x3 = -0.4;
131 if (isnan (expl (x1)) || isnan (expl (x2)) || isnan (expl (x3)))
132 result |= 2;
133 }
134 /* This test fails on musl 1.2.2/arm64, musl 1.2.2/s390x, NetBSD 9.3. */
135 {
136 const long double TWO_LDBL_MANT_DIG = /* 2^LDBL_MANT_DIG */
137 (long double) (1U << ((LDBL_MANT_DIG - 1) / 5))
138 * (long double) (1U << ((LDBL_MANT_DIG - 1 + 1) / 5))
139 * (long double) (1U << ((LDBL_MANT_DIG - 1 + 2) / 5))
140 * (long double) (1U << ((LDBL_MANT_DIG - 1 + 3) / 5))
141 * (long double) (1U << ((LDBL_MANT_DIG - 1 + 4) / 5));
142 long double x = 11.358L;
143 long double err = (my_expl (x) * my_expl (- x) - 1.0L) * TWO_LDBL_MANT_DIG;
144 if (!(err >= -100.0L && err <= 100.0L))
145 result |= 4;
146 }
147 return result;
148 }
149 ]])],
150 [gl_cv_func_expl_works=yes],
151 [gl_cv_func_expl_works=no],
152 [case "$host_os" in
153 # Guess yes on glibc systems.
154 *-gnu* | gnu*) gl_cv_func_expl_works="guessing yes" ;;
155 # Guess no on musl systems.
156 *-musl* | midipix*) gl_cv_func_expl_works="guessing no" ;;
157 # Guess yes on native Windows.
158 mingw* | windows*) gl_cv_func_expl_works="guessing yes" ;;
159 # If we don't know, obey --enable-cross-guesses.
160 *) gl_cv_func_expl_works="$gl_cross_guess_normal" ;;
161 esac
162 ])
163 LIBS="$saved_LIBS"
164 ])
165 case "$gl_cv_func_expl_works" in
166 *yes) ;;
167 *) REPLACE_EXPL=1 ;;
168 esac
169 fi
170 else
171 HAVE_DECL_EXPL=0
172 HAVE_EXPL=0
173 fi
174 if test $HAVE_EXPL = 0 || test $REPLACE_EXPL = 1; then
175 dnl Find libraries needed to link lib/expl.c.
176 if test $HAVE_SAME_LONG_DOUBLE_AS_DOUBLE = 1; then
177 AC_REQUIRE([gl_FUNC_EXP])
178 EXPL_LIBM="$EXP_LIBM"
179 else
180 AC_REQUIRE([gl_FUNC_ISNANL])
181 AC_REQUIRE([gl_FUNC_ROUNDL])
182 AC_REQUIRE([gl_FUNC_LDEXPL])
183 EXPL_LIBM=
184 dnl Append $ISNANL_LIBM to EXPL_LIBM, avoiding gratuitous duplicates.
185 case " $EXPL_LIBM " in
186 *" $ISNANL_LIBM "*) ;;
187 *) EXPL_LIBM="$EXPL_LIBM $ISNANL_LIBM" ;;
188 esac
189 dnl Append $ROUNDL_LIBM to EXPL_LIBM, avoiding gratuitous duplicates.
190 case " $EXPL_LIBM " in
191 *" $ROUNDL_LIBM "*) ;;
192 *) EXPL_LIBM="$EXPL_LIBM $ROUNDL_LIBM" ;;
193 esac
194 dnl Append $LDEXPL_LIBM to EXPL_LIBM, avoiding gratuitous duplicates.
195 case " $EXPL_LIBM " in
196 *" $LDEXPL_LIBM "*) ;;
197 *) EXPL_LIBM="$EXPL_LIBM $LDEXPL_LIBM" ;;
198 esac
199 fi
200 fi
201 AC_SUBST([EXPL_LIBM])
202 ])