Debian Codegraph @

m4/frexpl.m4

raw
1 # frexpl.m4
2 # serial 24
3 dnl Copyright (C) 2007-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_FREXPL],
10 [
11 AC_REQUIRE([gl_MATH_H_DEFAULTS])
12 AC_REQUIRE([gl_LONG_DOUBLE_VS_DOUBLE])
13
14 dnl Persuade glibc <math.h> to declare frexpl().
15 AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
16
17 dnl Check whether it's declared.
18 dnl Mac OS X 10.3 has frexpl() in libc but doesn't declare it in <math.h>.
19 AC_CHECK_DECL([frexpl], , [HAVE_DECL_FREXPL=0], [[#include <math.h>]])
20
21 FREXPL_LIBM=
22 if test $HAVE_DECL_FREXPL = 1; then
23 gl_CHECK_FREXPL_NO_LIBM
24 if test $gl_cv_func_frexpl_no_libm = no; then
25 AC_CACHE_CHECK([whether frexpl() can be used with libm],
26 [gl_cv_func_frexpl_in_libm],
27 [
28 saved_LIBS="$LIBS"
29 LIBS="$LIBS -lm"
30 AC_LINK_IFELSE(
31 [AC_LANG_PROGRAM(
32 [[#include <math.h>
33 long double x;]],
34 [[int e; return frexpl (x, &e) > 0;]])],
35 [gl_cv_func_frexpl_in_libm=yes],
36 [gl_cv_func_frexpl_in_libm=no])
37 LIBS="$saved_LIBS"
38 ])
39 if test $gl_cv_func_frexpl_in_libm = yes; then
40 FREXPL_LIBM=-lm
41 fi
42 fi
43 if test $gl_cv_func_frexpl_no_libm = yes \
44 || test $gl_cv_func_frexpl_in_libm = yes; then
45 saved_LIBS="$LIBS"
46 LIBS="$LIBS $FREXPL_LIBM"
47 gl_FUNC_FREXPL_WORKS
48 LIBS="$saved_LIBS"
49 case "$gl_cv_func_frexpl_works" in
50 *yes) gl_func_frexpl=yes ;;
51 *) gl_func_frexpl=no; REPLACE_FREXPL=1 ;;
52 esac
53 else
54 gl_func_frexpl=no
55 fi
56 if test $gl_func_frexpl = yes; then
57 AC_DEFINE([HAVE_FREXPL], [1],
58 [Define if the frexpl() function is available.])
59 fi
60 fi
61 if test $HAVE_DECL_FREXPL = 0 || test $gl_func_frexpl = no; then
62 dnl Find libraries needed to link lib/frexpl.c.
63 if test $HAVE_SAME_LONG_DOUBLE_AS_DOUBLE = 1; then
64 AC_REQUIRE([gl_FUNC_FREXP])
65 FREXPL_LIBM="$FREXP_LIBM"
66 else
67 FREXPL_LIBM=
68 fi
69 fi
70 AC_SUBST([FREXPL_LIBM])
71 ])
72
73 AC_DEFUN([gl_FUNC_FREXPL_NO_LIBM],
74 [
75 AC_REQUIRE([gl_MATH_H_DEFAULTS])
76 AC_REQUIRE([gl_LONG_DOUBLE_VS_DOUBLE])
77 dnl Check whether it's declared.
78 dnl Mac OS X 10.3 has frexpl() in libc but doesn't declare it in <math.h>.
79 AC_CHECK_DECL([frexpl], , [HAVE_DECL_FREXPL=0], [[#include <math.h>]])
80 if test $HAVE_DECL_FREXPL = 1; then
81 gl_CHECK_FREXPL_NO_LIBM
82 if test $gl_cv_func_frexpl_no_libm = yes; then
83 gl_FUNC_FREXPL_WORKS
84 case "$gl_cv_func_frexpl_works" in
85 *yes) gl_func_frexpl_no_libm=yes ;;
86 *) gl_func_frexpl_no_libm=no; REPLACE_FREXPL=1 ;;
87 esac
88 else
89 gl_func_frexpl_no_libm=no
90 dnl Set REPLACE_FREXPL here because the system may have frexpl in libm.
91 REPLACE_FREXPL=1
92 fi
93 if test $gl_func_frexpl_no_libm = yes; then
94 AC_DEFINE([HAVE_FREXPL_IN_LIBC], [1],
95 [Define if the frexpl() function is available in libc.])
96 fi
97 fi
98 ])
99
100 dnl Test whether frexpl() can be used without linking with libm.
101 dnl Set gl_cv_func_frexpl_no_libm to 'yes' or 'no' accordingly.
102 AC_DEFUN([gl_CHECK_FREXPL_NO_LIBM],
103 [
104 AC_CACHE_CHECK([whether frexpl() can be used without linking with libm],
105 [gl_cv_func_frexpl_no_libm],
106 [
107 AC_LINK_IFELSE(
108 [AC_LANG_PROGRAM(
109 [[#include <math.h>
110 long double x;]],
111 [[int e; return frexpl (x, &e) > 0;]])],
112 [gl_cv_func_frexpl_no_libm=yes],
113 [gl_cv_func_frexpl_no_libm=no])
114 ])
115 ])
116
117 dnl Test whether frexpl() works on finite numbers (this fails on
118 dnl Mac OS X 10.4/PowerPC, on AIX 5.1, and on BeOS), on denormalized numbers
119 dnl (this fails on Mac OS X 10.5/i386), and also on infinite numbers (this
120 dnl fails e.g. on IRIX 6.5 and mingw).
121 AC_DEFUN([gl_FUNC_FREXPL_WORKS],
122 [
123 AC_REQUIRE([AC_PROG_CC])
124 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
125 AC_CACHE_CHECK([whether frexpl works], [gl_cv_func_frexpl_works],
126 [
127 AC_RUN_IFELSE(
128 [AC_LANG_SOURCE([[
129 #include <float.h>
130 #include <math.h>
131 /* Override the values of <float.h>, like done in float.in.h. */
132 #if defined __i386__ && (defined __BEOS__ || defined __OpenBSD__)
133 # undef LDBL_MIN_EXP
134 # define LDBL_MIN_EXP (-16381)
135 #endif
136 #if defined __i386__ && (defined __FreeBSD__ || defined __DragonFly__)
137 # undef LDBL_MIN_EXP
138 # define LDBL_MIN_EXP (-16381)
139 #endif
140 #if (defined _ARCH_PPC || defined _POWER) && defined _AIX && (LDBL_MANT_DIG == 106) && defined __GNUC__
141 # undef LDBL_MIN_EXP
142 # define LDBL_MIN_EXP DBL_MIN_EXP
143 #endif
144 #if defined __sgi && (LDBL_MANT_DIG >= 106)
145 # if defined __GNUC__
146 # undef LDBL_MIN_EXP
147 # define LDBL_MIN_EXP DBL_MIN_EXP
148 # endif
149 #endif
150 extern
151 #ifdef __cplusplus
152 "C"
153 #endif
154 long double frexpl (long double, int *);
155 long double zero = 0.0L;
156 int main()
157 {
158 int result = 0;
159 volatile long double x;
160 /* Test on finite numbers that fails on AIX 5.1. */
161 x = 16.0L;
162 {
163 int exp = -9999;
164 frexpl (x, &exp);
165 if (exp != 5)
166 result |= 1;
167 }
168 /* Test on finite numbers that fails on Mac OS X 10.4, because its frexpl
169 function returns an invalid (incorrectly normalized) value: it returns
170 y = { 0x3fe028f5, 0xc28f5c28, 0x3c9eb851, 0xeb851eb8 }
171 but the correct result is
172 0.505L = { 0x3fe028f5, 0xc28f5c29, 0xbc547ae1, 0x47ae1480 } */
173 x = 1.01L;
174 {
175 int exp = -9999;
176 long double y = frexpl (x, &exp);
177 if (!(exp == 1 && y == 0.505L))
178 result |= 2;
179 }
180 /* Test on large finite numbers. This fails on BeOS at i = 16322, while
181 LDBL_MAX_EXP = 16384.
182 In the loop end test, we test x against Infinity, rather than comparing
183 i with LDBL_MAX_EXP, because BeOS <float.h> has a wrong LDBL_MAX_EXP. */
184 {
185 int i;
186 for (i = 1, x = 1.0L; x != x + x; i++, x *= 2.0L)
187 {
188 int exp = -9999;
189 frexpl (x, &exp);
190 if (exp != i)
191 {
192 result |= 4;
193 break;
194 }
195 }
196 }
197 /* Test on denormalized numbers. */
198 {
199 int i;
200 for (i = 1, x = 1.0L; i >= LDBL_MIN_EXP; i--, x *= 0.5L)
201 ;
202 if (x > 0.0L)
203 {
204 int exp;
205 long double y = frexpl (x, &exp);
206 /* On machines with IEEE854 arithmetic: x = 1.68105e-4932,
207 exp = -16382, y = 0.5. On Mac OS X 10.5: exp = -16384, y = 0.5. */
208 if (exp != LDBL_MIN_EXP - 1)
209 result |= 8;
210 }
211 }
212 /* Test on infinite numbers. */
213 /* The Microsoft MSVC 14 compiler chokes on the expression 1.0 / 0.0. */
214 x = 1.0L / zero;
215 {
216 int exp;
217 long double y = frexpl (x, &exp);
218 if (y != x)
219 result |= 16;
220 }
221 return result;
222 }]])],
223 [gl_cv_func_frexpl_works=yes],
224 [gl_cv_func_frexpl_works=no],
225 [
226 changequote(,)dnl
227 case "$host_os" in
228 aix | aix[3-6]* | beos* | darwin* | irix* | mingw* | windows* | pw*)
229 gl_cv_func_frexpl_works="guessing no";;
230 *) gl_cv_func_frexpl_works="guessing yes";;
231 esac
232 changequote([,])dnl
233 ])
234 ])
235 ])