]>
Commit | Line | Data |
---|---|---|
f7eac6eb | 1 | /* Declarations for math functions. |
2b778ceb | 2 | Copyright (C) 1991-2021 Free Software Foundation, Inc. |
ba1ffaa1 | 3 | This file is part of the GNU C Library. |
28f540f4 | 4 | |
ba1ffaa1 | 5 | The GNU C Library is free software; you can redistribute it and/or |
41bdb6e2 AJ |
6 | modify it under the terms of the GNU Lesser General Public |
7 | License as published by the Free Software Foundation; either | |
8 | version 2.1 of the License, or (at your option) any later version. | |
28f540f4 | 9 | |
ba1ffaa1 UD |
10 | The GNU C Library is distributed in the hope that it will be useful, |
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
41bdb6e2 | 13 | Lesser General Public License for more details. |
28f540f4 | 14 | |
41bdb6e2 | 15 | You should have received a copy of the GNU Lesser General Public |
59ba27a6 | 16 | License along with the GNU C Library; if not, see |
5a82c748 | 17 | <https://www.gnu.org/licenses/>. */ |
28f540f4 RM |
18 | |
19 | /* | |
d1646309 | 20 | * ISO C99 Standard: 7.12 Mathematics <math.h> |
28f540f4 RM |
21 | */ |
22 | ||
23 | #ifndef _MATH_H | |
28f540f4 | 24 | #define _MATH_H 1 |
5107cf1d | 25 | |
bf91be88 JM |
26 | #define __GLIBC_INTERNAL_STARTING_HEADER_IMPLEMENTATION |
27 | #include <bits/libc-header-start.h> | |
28f540f4 | 28 | |
b38042f5 FW |
29 | #if defined log && defined __GNUC__ |
30 | # warning A macro called log was already defined when <math.h> was included. | |
31 | # warning This will cause compilation problems. | |
32 | #endif | |
33 | ||
28f540f4 RM |
34 | __BEGIN_DECLS |
35 | ||
423c2b9d JM |
36 | /* Get definitions of __intmax_t and __uintmax_t. */ |
37 | #include <bits/types.h> | |
38 | ||
202d48da AS |
39 | /* Get machine-dependent vector math functions declarations. */ |
40 | #include <bits/math-vector.h> | |
41 | ||
fcee5905 PM |
42 | /* Gather machine dependent type support. */ |
43 | #include <bits/floatn.h> | |
44 | ||
a617bd11 ZW |
45 | /* Value returned on overflow. With IEEE 754 floating point, this is |
46 | +Infinity, otherwise the largest representable positive value. */ | |
a60eca2e JM |
47 | #if __GNUC_PREREQ (3, 3) |
48 | # define HUGE_VAL (__builtin_huge_val ()) | |
49 | #else | |
a617bd11 ZW |
50 | /* This may provoke compiler warnings, and may not be rounded to |
51 | +Infinity in all IEEE 754 rounding modes, but is the best that can | |
52 | be done in ISO C while remaining a constant expression. 10,000 is | |
53 | greater than the maximum (decimal) exponent for all supported | |
54 | floating-point formats and widths. */ | |
a60eca2e JM |
55 | # define HUGE_VAL 1e10000 |
56 | #endif | |
57 | #ifdef __USE_ISOC99 | |
58 | # if __GNUC_PREREQ (3, 3) | |
59 | # define HUGE_VALF (__builtin_huge_valf ()) | |
60 | # define HUGE_VALL (__builtin_huge_vall ()) | |
61 | # else | |
62 | # define HUGE_VALF 1e10000f | |
63 | # define HUGE_VALL 1e10000L | |
64 | # endif | |
65 | #endif | |
5d220788 JM |
66 | #if __HAVE_FLOAT16 && __GLIBC_USE (IEC_60559_TYPES_EXT) |
67 | # define HUGE_VAL_F16 (__builtin_huge_valf16 ()) | |
68 | #endif | |
69 | #if __HAVE_FLOAT32 && __GLIBC_USE (IEC_60559_TYPES_EXT) | |
70 | # define HUGE_VAL_F32 (__builtin_huge_valf32 ()) | |
71 | #endif | |
72 | #if __HAVE_FLOAT64 && __GLIBC_USE (IEC_60559_TYPES_EXT) | |
73 | # define HUGE_VAL_F64 (__builtin_huge_valf64 ()) | |
74 | #endif | |
fcee5905 | 75 | #if __HAVE_FLOAT128 && __GLIBC_USE (IEC_60559_TYPES_EXT) |
a60eca2e | 76 | # define HUGE_VAL_F128 (__builtin_huge_valf128 ()) |
fcee5905 | 77 | #endif |
5d220788 JM |
78 | #if __HAVE_FLOAT32X && __GLIBC_USE (IEC_60559_TYPES_EXT) |
79 | # define HUGE_VAL_F32X (__builtin_huge_valf32x ()) | |
80 | #endif | |
81 | #if __HAVE_FLOAT64X && __GLIBC_USE (IEC_60559_TYPES_EXT) | |
82 | # define HUGE_VAL_F64X (__builtin_huge_valf64x ()) | |
83 | #endif | |
84 | #if __HAVE_FLOAT128X && __GLIBC_USE (IEC_60559_TYPES_EXT) | |
85 | # define HUGE_VAL_F128X (__builtin_huge_valf128x ()) | |
86 | #endif | |
fcee5905 | 87 | |
a86573f4 | 88 | #ifdef __USE_ISOC99 |
5ef1b213 JM |
89 | /* IEEE positive infinity. */ |
90 | # if __GNUC_PREREQ (3, 3) | |
91 | # define INFINITY (__builtin_inff ()) | |
92 | # else | |
93 | # define INFINITY HUGE_VALF | |
94 | # endif | |
28f540f4 | 95 | |
c0c49d60 JM |
96 | /* IEEE Not A Number. */ |
97 | # if __GNUC_PREREQ (3, 3) | |
98 | # define NAN (__builtin_nanf ("")) | |
99 | # else | |
100 | /* This will raise an "invalid" exception outside static initializers, | |
101 | but is the best that can be done in ISO C while remaining a | |
102 | constant expression. */ | |
103 | # define NAN (0.0f / 0.0f) | |
104 | # endif | |
a86573f4 RH |
105 | #endif /* __USE_ISOC99 */ |
106 | ||
858045ad | 107 | #if __GLIBC_USE (IEC_60559_BFP_EXT) |
f82a4bdb JM |
108 | /* Signaling NaN macros, if supported. */ |
109 | # if __GNUC_PREREQ (3, 3) | |
110 | # define SNANF (__builtin_nansf ("")) | |
111 | # define SNAN (__builtin_nans ("")) | |
112 | # define SNANL (__builtin_nansl ("")) | |
113 | # endif | |
114 | #endif | |
858045ad JM |
115 | #if (__HAVE_FLOAT16 \ |
116 | && __GLIBC_USE (IEC_60559_TYPES_EXT) \ | |
117 | && (defined __USE_GNU || !__GLIBC_USE (ISOC2X))) | |
ecc7da5b JM |
118 | # define SNANF16 (__builtin_nansf16 ("")) |
119 | #endif | |
858045ad JM |
120 | #if (__HAVE_FLOAT32 \ |
121 | && __GLIBC_USE (IEC_60559_TYPES_EXT) \ | |
122 | && (defined __USE_GNU || !__GLIBC_USE (ISOC2X))) | |
ecc7da5b JM |
123 | # define SNANF32 (__builtin_nansf32 ("")) |
124 | #endif | |
858045ad JM |
125 | #if (__HAVE_FLOAT64 \ |
126 | && __GLIBC_USE (IEC_60559_TYPES_EXT) \ | |
127 | && (defined __USE_GNU || !__GLIBC_USE (ISOC2X))) | |
ecc7da5b JM |
128 | # define SNANF64 (__builtin_nansf64 ("")) |
129 | #endif | |
858045ad JM |
130 | #if (__HAVE_FLOAT128 \ |
131 | && __GLIBC_USE (IEC_60559_TYPES_EXT) \ | |
132 | && (defined __USE_GNU || !__GLIBC_USE (ISOC2X))) | |
302bb1a3 PM |
133 | # define SNANF128 (__builtin_nansf128 ("")) |
134 | #endif | |
858045ad JM |
135 | #if (__HAVE_FLOAT32X \ |
136 | && __GLIBC_USE (IEC_60559_TYPES_EXT) \ | |
137 | && (defined __USE_GNU || !__GLIBC_USE (ISOC2X))) | |
ecc7da5b JM |
138 | # define SNANF32X (__builtin_nansf32x ("")) |
139 | #endif | |
858045ad JM |
140 | #if (__HAVE_FLOAT64X \ |
141 | && __GLIBC_USE (IEC_60559_TYPES_EXT) \ | |
142 | && (defined __USE_GNU || !__GLIBC_USE (ISOC2X))) | |
ecc7da5b JM |
143 | # define SNANF64X (__builtin_nansf64x ("")) |
144 | #endif | |
858045ad JM |
145 | #if (__HAVE_FLOAT128X \ |
146 | && __GLIBC_USE (IEC_60559_TYPES_EXT) \ | |
147 | && (defined __USE_GNU || !__GLIBC_USE (ISOC2X))) | |
ecc7da5b JM |
148 | # define SNANF128X (__builtin_nansf128x ("")) |
149 | #endif | |
f82a4bdb | 150 | |
93eb85ce JM |
151 | /* Get __GLIBC_FLT_EVAL_METHOD. */ |
152 | #include <bits/flt-eval-method.h> | |
153 | ||
154 | #ifdef __USE_ISOC99 | |
155 | /* Define the following typedefs. | |
89a12e6f JM |
156 | |
157 | float_t floating-point type at least as wide as `float' used | |
158 | to evaluate `float' expressions | |
159 | double_t floating-point type at least as wide as `double' used | |
160 | to evaluate `double' expressions | |
93eb85ce JM |
161 | */ |
162 | # if __GLIBC_FLT_EVAL_METHOD == 0 || __GLIBC_FLT_EVAL_METHOD == 16 | |
163 | typedef float float_t; | |
164 | typedef double double_t; | |
165 | # elif __GLIBC_FLT_EVAL_METHOD == 1 | |
166 | typedef double float_t; | |
167 | typedef double double_t; | |
168 | # elif __GLIBC_FLT_EVAL_METHOD == 2 | |
169 | typedef long double float_t; | |
170 | typedef long double double_t; | |
171 | # elif __GLIBC_FLT_EVAL_METHOD == 32 | |
172 | typedef _Float32 float_t; | |
173 | typedef double double_t; | |
174 | # elif __GLIBC_FLT_EVAL_METHOD == 33 | |
175 | typedef _Float32x float_t; | |
176 | typedef _Float32x double_t; | |
177 | # elif __GLIBC_FLT_EVAL_METHOD == 64 | |
178 | typedef _Float64 float_t; | |
179 | typedef _Float64 double_t; | |
180 | # elif __GLIBC_FLT_EVAL_METHOD == 65 | |
181 | typedef _Float64x float_t; | |
182 | typedef _Float64x double_t; | |
183 | # elif __GLIBC_FLT_EVAL_METHOD == 128 | |
184 | typedef _Float128 float_t; | |
185 | typedef _Float128 double_t; | |
186 | # elif __GLIBC_FLT_EVAL_METHOD == 129 | |
187 | typedef _Float128x float_t; | |
188 | typedef _Float128x double_t; | |
189 | # else | |
190 | # error "Unknown __GLIBC_FLT_EVAL_METHOD" | |
191 | # endif | |
192 | #endif | |
193 | ||
55a38f82 | 194 | /* Define macros for the return values of ilogb and llogb, based on |
b2491db6 | 195 | __FP_LOGB0_IS_MIN and __FP_LOGBNAN_IS_MIN. |
f11e220d JM |
196 | |
197 | FP_ILOGB0 Expands to a value returned by `ilogb (0.0)'. | |
198 | FP_ILOGBNAN Expands to a value returned by `ilogb (NAN)'. | |
55a38f82 JM |
199 | FP_LLOGB0 Expands to a value returned by `llogb (0.0)'. |
200 | FP_LLOGBNAN Expands to a value returned by `llogb (NAN)'. | |
f11e220d JM |
201 | |
202 | */ | |
203 | ||
b2491db6 JM |
204 | #include <bits/fp-logb.h> |
205 | #ifdef __USE_ISOC99 | |
206 | # if __FP_LOGB0_IS_MIN | |
207 | # define FP_ILOGB0 (-2147483647 - 1) | |
208 | # else | |
209 | # define FP_ILOGB0 (-2147483647) | |
210 | # endif | |
211 | # if __FP_LOGBNAN_IS_MIN | |
212 | # define FP_ILOGBNAN (-2147483647 - 1) | |
213 | # else | |
214 | # define FP_ILOGBNAN 2147483647 | |
215 | # endif | |
216 | #endif | |
0175c9e9 | 217 | #if __GLIBC_USE (IEC_60559_BFP_EXT_C2X) |
55a38f82 JM |
218 | # if __WORDSIZE == 32 |
219 | # define __FP_LONG_MAX 0x7fffffffL | |
220 | # else | |
221 | # define __FP_LONG_MAX 0x7fffffffffffffffL | |
222 | # endif | |
223 | # if __FP_LOGB0_IS_MIN | |
224 | # define FP_LLOGB0 (-__FP_LONG_MAX - 1) | |
225 | # else | |
226 | # define FP_LLOGB0 (-__FP_LONG_MAX) | |
227 | # endif | |
228 | # if __FP_LOGBNAN_IS_MIN | |
229 | # define FP_LLOGBNAN (-__FP_LONG_MAX - 1) | |
230 | # else | |
231 | # define FP_LLOGBNAN __FP_LONG_MAX | |
232 | # endif | |
233 | #endif | |
b2491db6 | 234 | |
93eb85ce JM |
235 | /* Get the architecture specific values describing the floating-point |
236 | evaluation. The following symbols will get defined: | |
89a12e6f JM |
237 | |
238 | FP_FAST_FMA | |
239 | FP_FAST_FMAF | |
240 | FP_FAST_FMAL | |
241 | If defined it indicates that the `fma' function | |
242 | generally executes about as fast as a multiply and an add. | |
243 | This macro is defined only iff the `fma' function is | |
244 | implemented directly with a hardware multiply-add instructions. | |
89a12e6f JM |
245 | */ |
246 | ||
f11e220d | 247 | #include <bits/fp-fast.h> |
28f540f4 | 248 | |
0175c9e9 | 249 | #if __GLIBC_USE (IEC_60559_BFP_EXT_C2X) |
423c2b9d JM |
250 | /* Rounding direction macros for fromfp functions. */ |
251 | enum | |
252 | { | |
253 | FP_INT_UPWARD = | |
254 | # define FP_INT_UPWARD 0 | |
255 | FP_INT_UPWARD, | |
256 | FP_INT_DOWNWARD = | |
257 | # define FP_INT_DOWNWARD 1 | |
258 | FP_INT_DOWNWARD, | |
259 | FP_INT_TOWARDZERO = | |
260 | # define FP_INT_TOWARDZERO 2 | |
261 | FP_INT_TOWARDZERO, | |
262 | FP_INT_TONEARESTFROMZERO = | |
263 | # define FP_INT_TONEARESTFROMZERO 3 | |
264 | FP_INT_TONEARESTFROMZERO, | |
265 | FP_INT_TONEAREST = | |
266 | # define FP_INT_TONEAREST 4 | |
267 | FP_INT_TONEAREST, | |
268 | }; | |
269 | #endif | |
270 | ||
5107cf1d UD |
271 | /* The file <bits/mathcalls.h> contains the prototypes for all the |
272 | actual math functions. These macros are used for those prototypes, | |
273 | so we can easily declare each function as both `name' and `__name', | |
f7eac6eb RM |
274 | and can declare the float versions `namef' and `__namef'. */ |
275 | ||
202d48da AS |
276 | #define __SIMD_DECL(function) __CONCAT (__DECL_SIMD_, function) |
277 | ||
278 | #define __MATHCALL_VEC(function, suffix, args) \ | |
279 | __SIMD_DECL (__MATH_PRECNAME (function, suffix)) \ | |
280 | __MATHCALL (function, suffix, args) | |
281 | ||
c9a8c526 AS |
282 | #define __MATHDECL_VEC(type, function,suffix, args) \ |
283 | __SIMD_DECL (__MATH_PRECNAME (function, suffix)) \ | |
284 | __MATHDECL(type, function,suffix, args) | |
285 | ||
f7eac6eb | 286 | #define __MATHCALL(function,suffix, args) \ |
377a515b | 287 | __MATHDECL (_Mdouble_,function,suffix, args) |
f7eac6eb RM |
288 | #define __MATHDECL(type, function,suffix, args) \ |
289 | __MATHDECL_1(type, function,suffix, args); \ | |
377a515b | 290 | __MATHDECL_1(type, __CONCAT(__,function),suffix, args) |
3e5f5557 UD |
291 | #define __MATHCALLX(function,suffix, args, attrib) \ |
292 | __MATHDECLX (_Mdouble_,function,suffix, args, attrib) | |
293 | #define __MATHDECLX(type, function,suffix, args, attrib) \ | |
294 | __MATHDECL_1(type, function,suffix, args) __attribute__ (attrib); \ | |
295 | __MATHDECL_1(type, __CONCAT(__,function),suffix, args) __attribute__ (attrib) | |
77ad9735 | 296 | #define __MATHDECL_1_IMPL(type, function, suffix, args) \ |
c1422e5b | 297 | extern type __MATH_PRECNAME(function,suffix) args __THROW |
77ad9735 TMQMF |
298 | #define __MATHDECL_1(type, function, suffix, args) \ |
299 | __MATHDECL_1_IMPL(type, function, suffix, args) | |
8dbfea3a TMQMF |
300 | /* Ignore the alias by default. The alias is only useful with |
301 | redirections. */ | |
302 | #define __MATHDECL_ALIAS(type, function, suffix, args, alias) \ | |
303 | __MATHDECL_1(type, function, suffix, args) | |
77ad9735 TMQMF |
304 | |
305 | #define __MATHREDIR(type, function, suffix, args, to) \ | |
306 | extern type __REDIRECT_NTH (__MATH_PRECNAME (function, suffix), args, to) | |
f7eac6eb | 307 | |
0ac5ae23 | 308 | #define _Mdouble_ double |
377a515b | 309 | #define __MATH_PRECNAME(name,r) __CONCAT(name,r) |
de20571d | 310 | #define __MATH_DECLARING_DOUBLE 1 |
fcee5905 | 311 | #define __MATH_DECLARING_FLOATN 0 |
ff80ec42 | 312 | #include <bits/mathcalls-helper-functions.h> |
5107cf1d | 313 | #include <bits/mathcalls.h> |
f7eac6eb RM |
314 | #undef _Mdouble_ |
315 | #undef __MATH_PRECNAME | |
de20571d | 316 | #undef __MATH_DECLARING_DOUBLE |
fcee5905 | 317 | #undef __MATH_DECLARING_FLOATN |
f7eac6eb | 318 | |
acd7f096 | 319 | #ifdef __USE_ISOC99 |
76060ec0 | 320 | |
999493cb RM |
321 | |
322 | /* Include the file of declarations again, this time using `float' | |
f7eac6eb RM |
323 | instead of `double' and appending f to each function name. */ |
324 | ||
eda162dd | 325 | # define _Mdouble_ float |
7071ad79 | 326 | # define __MATH_PRECNAME(name,r) name##f##r |
de20571d | 327 | # define __MATH_DECLARING_DOUBLE 0 |
fcee5905 | 328 | # define __MATH_DECLARING_FLOATN 0 |
ff80ec42 | 329 | # include <bits/mathcalls-helper-functions.h> |
478b92f0 UD |
330 | # include <bits/mathcalls.h> |
331 | # undef _Mdouble_ | |
332 | # undef __MATH_PRECNAME | |
de20571d | 333 | # undef __MATH_DECLARING_DOUBLE |
fcee5905 | 334 | # undef __MATH_DECLARING_FLOATN |
76060ec0 | 335 | |
7071ad79 | 336 | # if !(defined __NO_LONG_DOUBLE_MATH && defined _LIBC) \ |
dc6fe23b WN |
337 | || defined __LDBL_COMPAT \ |
338 | || defined _LIBC_TEST | |
c6251f03 RM |
339 | # ifdef __LDBL_COMPAT |
340 | ||
7b943af6 | 341 | # ifdef __USE_ISOC99 |
c6251f03 | 342 | extern float __nldbl_nexttowardf (float __x, long double __y) |
42247128 | 343 | __THROW __attribute__ ((__const__)); |
c6251f03 RM |
344 | # ifdef __REDIRECT_NTH |
345 | extern float __REDIRECT_NTH (nexttowardf, (float __x, long double __y), | |
346 | __nldbl_nexttowardf) | |
347 | __attribute__ ((__const__)); | |
348 | extern double __REDIRECT_NTH (nexttoward, (double __x, long double __y), | |
349 | nextafter) __attribute__ ((__const__)); | |
42247128 RM |
350 | extern long double __REDIRECT_NTH (nexttowardl, |
351 | (long double __x, long double __y), | |
352 | nextafter) __attribute__ ((__const__)); | |
c6251f03 RM |
353 | # endif |
354 | # endif | |
355 | ||
c6251f03 | 356 | # undef __MATHDECL_1 |
c6251f03 | 357 | # define __MATHDECL_1(type, function,suffix, args) \ |
77ad9735 | 358 | __MATHREDIR(type, function, suffix, args, __CONCAT(function,suffix)) |
8dbfea3a | 359 | |
e2239af3 | 360 | # elif __LDOUBLE_REDIRECTS_TO_FLOAT128_ABI == 1 |
8dbfea3a TMQMF |
361 | # ifdef __REDIRECT_NTH |
362 | # ifdef __USE_ISOC99 | |
363 | extern float __REDIRECT_NTH (nexttowardf, (float __x, long double __y), | |
364 | __nexttowardf_to_ieee128) | |
365 | __attribute__ ((__const__)); | |
366 | extern double __REDIRECT_NTH (nexttoward, (double __x, long double __y), | |
367 | __nexttoward_to_ieee128) | |
368 | __attribute__ ((__const__)); | |
369 | ||
370 | #define __dremieee128 __remainderieee128 | |
371 | #define __gammaieee128 __lgammaieee128 | |
372 | ||
373 | # endif | |
374 | # endif | |
375 | ||
376 | # undef __MATHDECL_1 | |
377 | # undef __MATHDECL_ALIAS | |
378 | ||
379 | # define __REDIRTO(function, suffix) \ | |
380 | __ ## function ## ieee128 ## suffix | |
381 | # define __REDIRTO_ALT(function, suffix) \ | |
382 | __ ## function ## f128 ## suffix | |
383 | ||
384 | # define __MATHDECL_1(type, function, suffix, args) \ | |
385 | __MATHREDIR (type, function, suffix, args, __REDIRTO (function, suffix)) | |
386 | # define __MATHDECL_ALIAS(type, function, suffix, args, alias) \ | |
387 | __MATHREDIR (type, function, suffix, args, __REDIRTO_ALT (alias, suffix)) | |
c6251f03 RM |
388 | # endif |
389 | ||
998832a4 AS |
390 | /* Include the file of declarations again, this time using `long double' |
391 | instead of `double' and appending l to each function name. */ | |
392 | ||
eda162dd | 393 | # define _Mdouble_ long double |
7071ad79 | 394 | # define __MATH_PRECNAME(name,r) name##l##r |
de20571d | 395 | # define __MATH_DECLARING_DOUBLE 0 |
fcee5905 | 396 | # define __MATH_DECLARING_FLOATN 0 |
0ac5ae23 | 397 | # define __MATH_DECLARE_LDOUBLE 1 |
ff80ec42 | 398 | # include <bits/mathcalls-helper-functions.h> |
fe0ec73e | 399 | # include <bits/mathcalls.h> |
8dbfea3a | 400 | |
fe0ec73e UD |
401 | # undef _Mdouble_ |
402 | # undef __MATH_PRECNAME | |
de20571d | 403 | # undef __MATH_DECLARING_DOUBLE |
fcee5905 | 404 | # undef __MATH_DECLARING_FLOATN |
fe0ec73e | 405 | |
8dbfea3a | 406 | # if defined __LDBL_COMPAT \ |
e2239af3 | 407 | || __LDOUBLE_REDIRECTS_TO_FLOAT128_ABI == 1 |
8dbfea3a TMQMF |
408 | # undef __REDIRTO |
409 | # undef __REDIRTO_ALT | |
77ad9735 | 410 | # undef __MATHDECL_1 |
8dbfea3a | 411 | # undef __MATHDECL_ALIAS |
77ad9735 TMQMF |
412 | # define __MATHDECL_1(type, function, suffix, args) \ |
413 | __MATHDECL_1_IMPL(type, function, suffix, args) | |
8dbfea3a TMQMF |
414 | # define __MATHDECL_ALIAS(type, function, suffix, args, alias) \ |
415 | __MATHDECL_1(type, function, suffix, args) | |
77ad9735 | 416 | # endif |
7071ad79 | 417 | # endif /* !(__NO_LONG_DOUBLE_MATH && _LIBC) || __LDBL_COMPAT */ |
377a515b | 418 | |
acd7f096 | 419 | #endif /* Use ISO C99. */ |
fcee5905 | 420 | |
7e9d7073 JM |
421 | /* Include the file of declarations for _FloatN and _FloatNx |
422 | types. */ | |
423 | ||
424 | #if __HAVE_DISTINCT_FLOAT16 || (__HAVE_FLOAT16 && !defined _LIBC) | |
eda162dd | 425 | # define _Mdouble_ _Float16 |
7e9d7073 JM |
426 | # define __MATH_PRECNAME(name,r) name##f16##r |
427 | # define __MATH_DECLARING_DOUBLE 0 | |
428 | # define __MATH_DECLARING_FLOATN 1 | |
429 | # if __HAVE_DISTINCT_FLOAT16 | |
430 | # include <bits/mathcalls-helper-functions.h> | |
431 | # endif | |
432 | # if __GLIBC_USE (IEC_60559_TYPES_EXT) | |
433 | # include <bits/mathcalls.h> | |
434 | # endif | |
435 | # undef _Mdouble_ | |
436 | # undef __MATH_PRECNAME | |
437 | # undef __MATH_DECLARING_DOUBLE | |
438 | # undef __MATH_DECLARING_FLOATN | |
439 | #endif /* __HAVE_DISTINCT_FLOAT16 || (__HAVE_FLOAT16 && !_LIBC). */ | |
440 | ||
441 | #if __HAVE_DISTINCT_FLOAT32 || (__HAVE_FLOAT32 && !defined _LIBC) | |
eda162dd | 442 | # define _Mdouble_ _Float32 |
7e9d7073 JM |
443 | # define __MATH_PRECNAME(name,r) name##f32##r |
444 | # define __MATH_DECLARING_DOUBLE 0 | |
445 | # define __MATH_DECLARING_FLOATN 1 | |
446 | # if __HAVE_DISTINCT_FLOAT32 | |
447 | # include <bits/mathcalls-helper-functions.h> | |
448 | # endif | |
449 | # if __GLIBC_USE (IEC_60559_TYPES_EXT) | |
450 | # include <bits/mathcalls.h> | |
451 | # endif | |
452 | # undef _Mdouble_ | |
453 | # undef __MATH_PRECNAME | |
454 | # undef __MATH_DECLARING_DOUBLE | |
455 | # undef __MATH_DECLARING_FLOATN | |
456 | #endif /* __HAVE_DISTINCT_FLOAT32 || (__HAVE_FLOAT32 && !_LIBC). */ | |
457 | ||
458 | #if __HAVE_DISTINCT_FLOAT64 || (__HAVE_FLOAT64 && !defined _LIBC) | |
eda162dd | 459 | # define _Mdouble_ _Float64 |
7e9d7073 JM |
460 | # define __MATH_PRECNAME(name,r) name##f64##r |
461 | # define __MATH_DECLARING_DOUBLE 0 | |
462 | # define __MATH_DECLARING_FLOATN 1 | |
463 | # if __HAVE_DISTINCT_FLOAT64 | |
464 | # include <bits/mathcalls-helper-functions.h> | |
465 | # endif | |
466 | # if __GLIBC_USE (IEC_60559_TYPES_EXT) | |
467 | # include <bits/mathcalls.h> | |
468 | # endif | |
469 | # undef _Mdouble_ | |
470 | # undef __MATH_PRECNAME | |
471 | # undef __MATH_DECLARING_DOUBLE | |
472 | # undef __MATH_DECLARING_FLOATN | |
473 | #endif /* __HAVE_DISTINCT_FLOAT64 || (__HAVE_FLOAT64 && !_LIBC). */ | |
fcee5905 PM |
474 | |
475 | #if __HAVE_DISTINCT_FLOAT128 || (__HAVE_FLOAT128 && !defined _LIBC) | |
eda162dd | 476 | # define _Mdouble_ _Float128 |
fcee5905 PM |
477 | # define __MATH_PRECNAME(name,r) name##f128##r |
478 | # define __MATH_DECLARING_DOUBLE 0 | |
479 | # define __MATH_DECLARING_FLOATN 1 | |
480 | # if __HAVE_DISTINCT_FLOAT128 | |
481 | # include <bits/mathcalls-helper-functions.h> | |
482 | # endif | |
483 | # if __GLIBC_USE (IEC_60559_TYPES_EXT) | |
484 | # include <bits/mathcalls.h> | |
485 | # endif | |
486 | # undef _Mdouble_ | |
487 | # undef __MATH_PRECNAME | |
488 | # undef __MATH_DECLARING_DOUBLE | |
489 | # undef __MATH_DECLARING_FLOATN | |
7e9d7073 JM |
490 | #endif /* __HAVE_DISTINCT_FLOAT128 || (__HAVE_FLOAT128 && !_LIBC). */ |
491 | ||
492 | #if __HAVE_DISTINCT_FLOAT32X || (__HAVE_FLOAT32X && !defined _LIBC) | |
eda162dd | 493 | # define _Mdouble_ _Float32x |
7e9d7073 JM |
494 | # define __MATH_PRECNAME(name,r) name##f32x##r |
495 | # define __MATH_DECLARING_DOUBLE 0 | |
496 | # define __MATH_DECLARING_FLOATN 1 | |
497 | # if __HAVE_DISTINCT_FLOAT32X | |
498 | # include <bits/mathcalls-helper-functions.h> | |
499 | # endif | |
500 | # if __GLIBC_USE (IEC_60559_TYPES_EXT) | |
501 | # include <bits/mathcalls.h> | |
502 | # endif | |
503 | # undef _Mdouble_ | |
504 | # undef __MATH_PRECNAME | |
505 | # undef __MATH_DECLARING_DOUBLE | |
506 | # undef __MATH_DECLARING_FLOATN | |
507 | #endif /* __HAVE_DISTINCT_FLOAT32X || (__HAVE_FLOAT32X && !_LIBC). */ | |
508 | ||
509 | #if __HAVE_DISTINCT_FLOAT64X || (__HAVE_FLOAT64X && !defined _LIBC) | |
eda162dd | 510 | # define _Mdouble_ _Float64x |
7e9d7073 JM |
511 | # define __MATH_PRECNAME(name,r) name##f64x##r |
512 | # define __MATH_DECLARING_DOUBLE 0 | |
513 | # define __MATH_DECLARING_FLOATN 1 | |
514 | # if __HAVE_DISTINCT_FLOAT64X | |
515 | # include <bits/mathcalls-helper-functions.h> | |
516 | # endif | |
517 | # if __GLIBC_USE (IEC_60559_TYPES_EXT) | |
518 | # include <bits/mathcalls.h> | |
519 | # endif | |
520 | # undef _Mdouble_ | |
521 | # undef __MATH_PRECNAME | |
522 | # undef __MATH_DECLARING_DOUBLE | |
523 | # undef __MATH_DECLARING_FLOATN | |
524 | #endif /* __HAVE_DISTINCT_FLOAT64X || (__HAVE_FLOAT64X && !_LIBC). */ | |
525 | ||
526 | #if __HAVE_DISTINCT_FLOAT128X || (__HAVE_FLOAT128X && !defined _LIBC) | |
eda162dd | 527 | # define _Mdouble_ _Float128x |
7e9d7073 JM |
528 | # define __MATH_PRECNAME(name,r) name##f128x##r |
529 | # define __MATH_DECLARING_DOUBLE 0 | |
530 | # define __MATH_DECLARING_FLOATN 1 | |
531 | # if __HAVE_DISTINCT_FLOAT128X | |
532 | # include <bits/mathcalls-helper-functions.h> | |
533 | # endif | |
534 | # if __GLIBC_USE (IEC_60559_TYPES_EXT) | |
535 | # include <bits/mathcalls.h> | |
536 | # endif | |
537 | # undef _Mdouble_ | |
538 | # undef __MATH_PRECNAME | |
539 | # undef __MATH_DECLARING_DOUBLE | |
540 | # undef __MATH_DECLARING_FLOATN | |
541 | #endif /* __HAVE_DISTINCT_FLOAT128X || (__HAVE_FLOAT128X && !_LIBC). */ | |
fcee5905 | 542 | |
77ad9735 | 543 | #undef __MATHDECL_1_IMPL |
4cca6b86 | 544 | #undef __MATHDECL_1 |
8dbfea3a | 545 | #undef __MATHDECL_ALIAS |
4cca6b86 UD |
546 | #undef __MATHDECL |
547 | #undef __MATHCALL | |
548 | ||
63716ab2 JM |
549 | /* Declare functions returning a narrower type. */ |
550 | #define __MATHCALL_NARROW_ARGS_1 (_Marg_ __x) | |
551 | #define __MATHCALL_NARROW_ARGS_2 (_Marg_ __x, _Marg_ __y) | |
552 | #define __MATHCALL_NARROW_ARGS_3 (_Marg_ __x, _Marg_ __y, _Marg_ __z) | |
553 | #define __MATHCALL_NARROW_NORMAL(func, nargs) \ | |
554 | extern _Mret_ func __MATHCALL_NARROW_ARGS_ ## nargs __THROW | |
555 | #define __MATHCALL_NARROW_REDIR(func, redir, nargs) \ | |
556 | extern _Mret_ __REDIRECT_NTH (func, __MATHCALL_NARROW_ARGS_ ## nargs, \ | |
557 | redir) | |
558 | #define __MATHCALL_NARROW(func, redir, nargs) \ | |
559 | __MATHCALL_NARROW_NORMAL (func, nargs) | |
560 | ||
0175c9e9 | 561 | #if __GLIBC_USE (IEC_60559_BFP_EXT_C2X) |
63716ab2 JM |
562 | |
563 | # define _Mret_ float | |
564 | # define _Marg_ double | |
565 | # define __MATHCALL_NAME(name) f ## name | |
566 | # include <bits/mathcalls-narrow.h> | |
567 | # undef _Mret_ | |
568 | # undef _Marg_ | |
569 | # undef __MATHCALL_NAME | |
570 | ||
571 | # define _Mret_ float | |
572 | # define _Marg_ long double | |
573 | # define __MATHCALL_NAME(name) f ## name ## l | |
574 | # ifdef __LDBL_COMPAT | |
575 | # define __MATHCALL_REDIR_NAME(name) f ## name | |
576 | # undef __MATHCALL_NARROW | |
8dbfea3a TMQMF |
577 | # define __MATHCALL_NARROW(func, redir, nargs) \ |
578 | __MATHCALL_NARROW_REDIR (func, redir, nargs) | |
e2239af3 | 579 | # elif __LDOUBLE_REDIRECTS_TO_FLOAT128_ABI == 1 |
8dbfea3a TMQMF |
580 | # define __MATHCALL_REDIR_NAME(name) __ ## f32 ## name ## ieee128 |
581 | # undef __MATHCALL_NARROW | |
63716ab2 JM |
582 | # define __MATHCALL_NARROW(func, redir, nargs) \ |
583 | __MATHCALL_NARROW_REDIR (func, redir, nargs) | |
584 | # endif | |
585 | # include <bits/mathcalls-narrow.h> | |
586 | # undef _Mret_ | |
587 | # undef _Marg_ | |
588 | # undef __MATHCALL_NAME | |
8dbfea3a | 589 | # if defined __LDBL_COMPAT \ |
e2239af3 | 590 | || __LDOUBLE_REDIRECTS_TO_FLOAT128_ABI == 1 |
63716ab2 JM |
591 | # undef __MATHCALL_REDIR_NAME |
592 | # undef __MATHCALL_NARROW | |
593 | # define __MATHCALL_NARROW(func, redir, nargs) \ | |
594 | __MATHCALL_NARROW_NORMAL (func, nargs) | |
595 | # endif | |
596 | ||
597 | # define _Mret_ double | |
598 | # define _Marg_ long double | |
599 | # define __MATHCALL_NAME(name) d ## name ## l | |
600 | # ifdef __LDBL_COMPAT | |
601 | # define __MATHCALL_REDIR_NAME(name) __nldbl_d ## name ## l | |
602 | # undef __MATHCALL_NARROW | |
8dbfea3a TMQMF |
603 | # define __MATHCALL_NARROW(func, redir, nargs) \ |
604 | __MATHCALL_NARROW_REDIR (func, redir, nargs) | |
e2239af3 | 605 | # elif __LDOUBLE_REDIRECTS_TO_FLOAT128_ABI == 1 |
8dbfea3a TMQMF |
606 | # define __MATHCALL_REDIR_NAME(name) __ ## f64 ## name ## ieee128 |
607 | # undef __MATHCALL_NARROW | |
63716ab2 JM |
608 | # define __MATHCALL_NARROW(func, redir, nargs) \ |
609 | __MATHCALL_NARROW_REDIR (func, redir, nargs) | |
610 | # endif | |
611 | # include <bits/mathcalls-narrow.h> | |
612 | # undef _Mret_ | |
613 | # undef _Marg_ | |
614 | # undef __MATHCALL_NAME | |
8dbfea3a | 615 | # if defined __LDBL_COMPAT \ |
e2239af3 | 616 | || __LDOUBLE_REDIRECTS_TO_FLOAT128_ABI == 1 |
63716ab2 JM |
617 | # undef __MATHCALL_REDIR_NAME |
618 | # undef __MATHCALL_NARROW | |
619 | # define __MATHCALL_NARROW(func, redir, nargs) \ | |
620 | __MATHCALL_NARROW_NORMAL (func, nargs) | |
621 | # endif | |
622 | ||
623 | #endif | |
624 | ||
625 | #if __GLIBC_USE (IEC_60559_TYPES_EXT) | |
626 | ||
627 | # if __HAVE_FLOAT16 && __HAVE_FLOAT32 | |
628 | # define _Mret_ _Float16 | |
629 | # define _Marg_ _Float32 | |
630 | # define __MATHCALL_NAME(name) f16 ## name ## f32 | |
631 | # include <bits/mathcalls-narrow.h> | |
632 | # undef _Mret_ | |
633 | # undef _Marg_ | |
634 | # undef __MATHCALL_NAME | |
635 | # endif | |
636 | ||
637 | # if __HAVE_FLOAT16 && __HAVE_FLOAT32X | |
638 | # define _Mret_ _Float16 | |
639 | # define _Marg_ _Float32x | |
640 | # define __MATHCALL_NAME(name) f16 ## name ## f32x | |
641 | # include <bits/mathcalls-narrow.h> | |
642 | # undef _Mret_ | |
643 | # undef _Marg_ | |
644 | # undef __MATHCALL_NAME | |
645 | # endif | |
646 | ||
647 | # if __HAVE_FLOAT16 && __HAVE_FLOAT64 | |
648 | # define _Mret_ _Float16 | |
649 | # define _Marg_ _Float64 | |
650 | # define __MATHCALL_NAME(name) f16 ## name ## f64 | |
651 | # include <bits/mathcalls-narrow.h> | |
652 | # undef _Mret_ | |
653 | # undef _Marg_ | |
654 | # undef __MATHCALL_NAME | |
655 | # endif | |
656 | ||
657 | # if __HAVE_FLOAT16 && __HAVE_FLOAT64X | |
658 | # define _Mret_ _Float16 | |
659 | # define _Marg_ _Float64x | |
660 | # define __MATHCALL_NAME(name) f16 ## name ## f64x | |
661 | # include <bits/mathcalls-narrow.h> | |
662 | # undef _Mret_ | |
663 | # undef _Marg_ | |
664 | # undef __MATHCALL_NAME | |
665 | # endif | |
666 | ||
667 | # if __HAVE_FLOAT16 && __HAVE_FLOAT128 | |
668 | # define _Mret_ _Float16 | |
669 | # define _Marg_ _Float128 | |
670 | # define __MATHCALL_NAME(name) f16 ## name ## f128 | |
671 | # include <bits/mathcalls-narrow.h> | |
672 | # undef _Mret_ | |
673 | # undef _Marg_ | |
674 | # undef __MATHCALL_NAME | |
675 | # endif | |
676 | ||
677 | # if __HAVE_FLOAT16 && __HAVE_FLOAT128X | |
678 | # define _Mret_ _Float16 | |
679 | # define _Marg_ _Float128x | |
680 | # define __MATHCALL_NAME(name) f16 ## name ## f128x | |
681 | # include <bits/mathcalls-narrow.h> | |
682 | # undef _Mret_ | |
683 | # undef _Marg_ | |
684 | # undef __MATHCALL_NAME | |
685 | # endif | |
686 | ||
687 | # if __HAVE_FLOAT32 && __HAVE_FLOAT32X | |
688 | # define _Mret_ _Float32 | |
689 | # define _Marg_ _Float32x | |
690 | # define __MATHCALL_NAME(name) f32 ## name ## f32x | |
691 | # include <bits/mathcalls-narrow.h> | |
692 | # undef _Mret_ | |
693 | # undef _Marg_ | |
694 | # undef __MATHCALL_NAME | |
695 | # endif | |
696 | ||
697 | # if __HAVE_FLOAT32 && __HAVE_FLOAT64 | |
698 | # define _Mret_ _Float32 | |
699 | # define _Marg_ _Float64 | |
700 | # define __MATHCALL_NAME(name) f32 ## name ## f64 | |
701 | # include <bits/mathcalls-narrow.h> | |
702 | # undef _Mret_ | |
703 | # undef _Marg_ | |
704 | # undef __MATHCALL_NAME | |
705 | # endif | |
706 | ||
707 | # if __HAVE_FLOAT32 && __HAVE_FLOAT64X | |
708 | # define _Mret_ _Float32 | |
709 | # define _Marg_ _Float64x | |
710 | # define __MATHCALL_NAME(name) f32 ## name ## f64x | |
711 | # include <bits/mathcalls-narrow.h> | |
712 | # undef _Mret_ | |
713 | # undef _Marg_ | |
714 | # undef __MATHCALL_NAME | |
715 | # endif | |
716 | ||
717 | # if __HAVE_FLOAT32 && __HAVE_FLOAT128 | |
718 | # define _Mret_ _Float32 | |
719 | # define _Marg_ _Float128 | |
720 | # define __MATHCALL_NAME(name) f32 ## name ## f128 | |
721 | # include <bits/mathcalls-narrow.h> | |
722 | # undef _Mret_ | |
723 | # undef _Marg_ | |
724 | # undef __MATHCALL_NAME | |
725 | # endif | |
726 | ||
727 | # if __HAVE_FLOAT32 && __HAVE_FLOAT128X | |
728 | # define _Mret_ _Float32 | |
729 | # define _Marg_ _Float128x | |
730 | # define __MATHCALL_NAME(name) f32 ## name ## f128x | |
731 | # include <bits/mathcalls-narrow.h> | |
732 | # undef _Mret_ | |
733 | # undef _Marg_ | |
734 | # undef __MATHCALL_NAME | |
735 | # endif | |
736 | ||
737 | # if __HAVE_FLOAT32X && __HAVE_FLOAT64 | |
738 | # define _Mret_ _Float32x | |
739 | # define _Marg_ _Float64 | |
740 | # define __MATHCALL_NAME(name) f32x ## name ## f64 | |
741 | # include <bits/mathcalls-narrow.h> | |
742 | # undef _Mret_ | |
743 | # undef _Marg_ | |
744 | # undef __MATHCALL_NAME | |
745 | # endif | |
746 | ||
747 | # if __HAVE_FLOAT32X && __HAVE_FLOAT64X | |
748 | # define _Mret_ _Float32x | |
749 | # define _Marg_ _Float64x | |
750 | # define __MATHCALL_NAME(name) f32x ## name ## f64x | |
751 | # include <bits/mathcalls-narrow.h> | |
752 | # undef _Mret_ | |
753 | # undef _Marg_ | |
754 | # undef __MATHCALL_NAME | |
755 | # endif | |
756 | ||
757 | # if __HAVE_FLOAT32X && __HAVE_FLOAT128 | |
758 | # define _Mret_ _Float32x | |
759 | # define _Marg_ _Float128 | |
760 | # define __MATHCALL_NAME(name) f32x ## name ## f128 | |
761 | # include <bits/mathcalls-narrow.h> | |
762 | # undef _Mret_ | |
763 | # undef _Marg_ | |
764 | # undef __MATHCALL_NAME | |
765 | # endif | |
766 | ||
767 | # if __HAVE_FLOAT32X && __HAVE_FLOAT128X | |
768 | # define _Mret_ _Float32x | |
769 | # define _Marg_ _Float128x | |
770 | # define __MATHCALL_NAME(name) f32x ## name ## f128x | |
771 | # include <bits/mathcalls-narrow.h> | |
772 | # undef _Mret_ | |
773 | # undef _Marg_ | |
774 | # undef __MATHCALL_NAME | |
775 | # endif | |
776 | ||
777 | # if __HAVE_FLOAT64 && __HAVE_FLOAT64X | |
778 | # define _Mret_ _Float64 | |
779 | # define _Marg_ _Float64x | |
780 | # define __MATHCALL_NAME(name) f64 ## name ## f64x | |
781 | # include <bits/mathcalls-narrow.h> | |
782 | # undef _Mret_ | |
783 | # undef _Marg_ | |
784 | # undef __MATHCALL_NAME | |
785 | # endif | |
786 | ||
787 | # if __HAVE_FLOAT64 && __HAVE_FLOAT128 | |
788 | # define _Mret_ _Float64 | |
789 | # define _Marg_ _Float128 | |
790 | # define __MATHCALL_NAME(name) f64 ## name ## f128 | |
791 | # include <bits/mathcalls-narrow.h> | |
792 | # undef _Mret_ | |
793 | # undef _Marg_ | |
794 | # undef __MATHCALL_NAME | |
795 | # endif | |
796 | ||
797 | # if __HAVE_FLOAT64 && __HAVE_FLOAT128X | |
798 | # define _Mret_ _Float64 | |
799 | # define _Marg_ _Float128x | |
800 | # define __MATHCALL_NAME(name) f64 ## name ## f128x | |
801 | # include <bits/mathcalls-narrow.h> | |
802 | # undef _Mret_ | |
803 | # undef _Marg_ | |
804 | # undef __MATHCALL_NAME | |
805 | # endif | |
806 | ||
807 | # if __HAVE_FLOAT64X && __HAVE_FLOAT128 | |
808 | # define _Mret_ _Float64x | |
809 | # define _Marg_ _Float128 | |
810 | # define __MATHCALL_NAME(name) f64x ## name ## f128 | |
811 | # include <bits/mathcalls-narrow.h> | |
812 | # undef _Mret_ | |
813 | # undef _Marg_ | |
814 | # undef __MATHCALL_NAME | |
815 | # endif | |
816 | ||
817 | # if __HAVE_FLOAT64X && __HAVE_FLOAT128X | |
818 | # define _Mret_ _Float64x | |
819 | # define _Marg_ _Float128x | |
820 | # define __MATHCALL_NAME(name) f64x ## name ## f128x | |
821 | # include <bits/mathcalls-narrow.h> | |
822 | # undef _Mret_ | |
823 | # undef _Marg_ | |
824 | # undef __MATHCALL_NAME | |
825 | # endif | |
826 | ||
827 | # if __HAVE_FLOAT128 && __HAVE_FLOAT128X | |
828 | # define _Mret_ _Float128 | |
829 | # define _Marg_ _Float128x | |
830 | # define __MATHCALL_NAME(name) f128 ## name ## f128x | |
831 | # include <bits/mathcalls-narrow.h> | |
832 | # undef _Mret_ | |
833 | # undef _Marg_ | |
834 | # undef __MATHCALL_NAME | |
835 | # endif | |
836 | ||
837 | #endif | |
838 | ||
839 | #undef __MATHCALL_NARROW_ARGS_1 | |
840 | #undef __MATHCALL_NARROW_ARGS_2 | |
841 | #undef __MATHCALL_NARROW_ARGS_3 | |
842 | #undef __MATHCALL_NARROW_NORMAL | |
843 | #undef __MATHCALL_NARROW_REDIR | |
844 | #undef __MATHCALL_NARROW | |
4cca6b86 | 845 | |
00d8bc81 | 846 | #if defined __USE_MISC || defined __USE_XOPEN |
4cca6b86 UD |
847 | /* This variable is used by `gamma' and `lgamma'. */ |
848 | extern int signgam; | |
849 | #endif | |
377a515b | 850 | |
4ca70e1a JM |
851 | #if (__HAVE_DISTINCT_FLOAT16 \ |
852 | || __HAVE_DISTINCT_FLOAT32 \ | |
853 | || __HAVE_DISTINCT_FLOAT64 \ | |
854 | || __HAVE_DISTINCT_FLOAT32X \ | |
855 | || __HAVE_DISTINCT_FLOAT64X \ | |
856 | || __HAVE_DISTINCT_FLOAT128X) | |
857 | # error "Unsupported _FloatN or _FloatNx types for <math.h>." | |
858 | #endif | |
377a515b | 859 | |
b4e75104 JM |
860 | /* Depending on the type of TG_ARG, call an appropriately suffixed |
861 | version of FUNC with arguments (including parentheses) ARGS. | |
862 | Suffixed functions may not exist for long double if it has the same | |
863 | format as double, or for other types with the same format as float, | |
864 | double or long double. The behavior is undefined if the argument | |
865 | does not have a real floating type. The definition may use a | |
866 | conditional expression, so all suffixed versions of FUNC must | |
867 | return the same type (FUNC may include a cast if necessary rather | |
868 | than being a single identifier). */ | |
869 | #ifdef __NO_LONG_DOUBLE_MATH | |
4ca70e1a JM |
870 | # if __HAVE_DISTINCT_FLOAT128 |
871 | # error "Distinct _Float128 without distinct long double not supported." | |
872 | # endif | |
b4e75104 JM |
873 | # define __MATH_TG(TG_ARG, FUNC, ARGS) \ |
874 | (sizeof (TG_ARG) == sizeof (float) ? FUNC ## f ARGS : FUNC ARGS) | |
477bf19a GG |
875 | #elif __HAVE_DISTINCT_FLOAT128 |
876 | # if __HAVE_GENERIC_SELECTION | |
4ca70e1a JM |
877 | # if __HAVE_FLOATN_NOT_TYPEDEF && __HAVE_FLOAT32 |
878 | # define __MATH_TG_F32(FUNC, ARGS) _Float32: FUNC ## f ARGS, | |
879 | # else | |
880 | # define __MATH_TG_F32(FUNC, ARGS) | |
881 | # endif | |
882 | # if __HAVE_FLOATN_NOT_TYPEDEF && __HAVE_FLOAT64X | |
883 | # if __HAVE_FLOAT64X_LONG_DOUBLE | |
884 | # define __MATH_TG_F64X(FUNC, ARGS) _Float64x: FUNC ## l ARGS, | |
885 | # else | |
886 | # define __MATH_TG_F64X(FUNC, ARGS) _Float64x: FUNC ## f128 ARGS, | |
887 | # endif | |
888 | # else | |
889 | # define __MATH_TG_F64X(FUNC, ARGS) | |
890 | # endif | |
891 | # define __MATH_TG(TG_ARG, FUNC, ARGS) \ | |
477bf19a GG |
892 | _Generic ((TG_ARG), \ |
893 | float: FUNC ## f ARGS, \ | |
4ca70e1a | 894 | __MATH_TG_F32 (FUNC, ARGS) \ |
477bf19a GG |
895 | default: FUNC ARGS, \ |
896 | long double: FUNC ## l ARGS, \ | |
4ca70e1a | 897 | __MATH_TG_F64X (FUNC, ARGS) \ |
477bf19a GG |
898 | _Float128: FUNC ## f128 ARGS) |
899 | # else | |
4ca70e1a JM |
900 | # if __HAVE_FLOATN_NOT_TYPEDEF |
901 | # error "Non-typedef _FloatN but no _Generic." | |
902 | # endif | |
477bf19a GG |
903 | # define __MATH_TG(TG_ARG, FUNC, ARGS) \ |
904 | __builtin_choose_expr \ | |
905 | (__builtin_types_compatible_p (__typeof (TG_ARG), float), \ | |
906 | FUNC ## f ARGS, \ | |
907 | __builtin_choose_expr \ | |
908 | (__builtin_types_compatible_p (__typeof (TG_ARG), double), \ | |
909 | FUNC ARGS, \ | |
910 | __builtin_choose_expr \ | |
911 | (__builtin_types_compatible_p (__typeof (TG_ARG), long double), \ | |
912 | FUNC ## l ARGS, \ | |
913 | FUNC ## f128 ARGS))) | |
914 | # endif | |
b4e75104 JM |
915 | #else |
916 | # define __MATH_TG(TG_ARG, FUNC, ARGS) \ | |
917 | (sizeof (TG_ARG) == sizeof (float) \ | |
918 | ? FUNC ## f ARGS \ | |
919 | : sizeof (TG_ARG) == sizeof (double) \ | |
920 | ? FUNC ARGS \ | |
921 | : FUNC ## l ARGS) | |
922 | #endif | |
923 | ||
ec751a23 | 924 | /* ISO C99 defines some generic macros which work on any data type. */ |
638bed90 | 925 | #ifdef __USE_ISOC99 |
377a515b UD |
926 | |
927 | /* All floating-point numbers can be put in one of these categories. */ | |
928 | enum | |
929 | { | |
0155d5b2 JM |
930 | FP_NAN = |
931 | # define FP_NAN 0 | |
932 | FP_NAN, | |
933 | FP_INFINITE = | |
934 | # define FP_INFINITE 1 | |
935 | FP_INFINITE, | |
936 | FP_ZERO = | |
937 | # define FP_ZERO 2 | |
938 | FP_ZERO, | |
939 | FP_SUBNORMAL = | |
940 | # define FP_SUBNORMAL 3 | |
941 | FP_SUBNORMAL, | |
942 | FP_NORMAL = | |
943 | # define FP_NORMAL 4 | |
944 | FP_NORMAL | |
377a515b UD |
945 | }; |
946 | ||
8df4e219 WD |
947 | /* GCC bug 66462 means we cannot use the math builtins with -fsignaling-nan, |
948 | so disable builtins if this is enabled. When fixed in a newer GCC, | |
949 | the __SUPPORT_SNAN__ check may be skipped for those versions. */ | |
950 | ||
377a515b | 951 | /* Return number of classification appropriate for X. */ |
4997e8f3 AZ |
952 | # if ((__GNUC_PREREQ (4,4) && !defined __SUPPORT_SNAN__) \ |
953 | || __glibc_clang_prereq (2,8)) \ | |
c5c4a626 GG |
954 | && (!defined __OPTIMIZE_SIZE__ || defined __cplusplus) |
955 | /* The check for __cplusplus allows the use of the builtin, even | |
956 | when optimization for size is on. This is provided for | |
957 | libstdc++, only to let its configure test work when it is built | |
958 | with -Os. No further use of this definition of fpclassify is | |
959 | expected in C++ mode, since libstdc++ provides its own version | |
960 | of fpclassify in cmath (which undefines fpclassify). */ | |
8df4e219 WD |
961 | # define fpclassify(x) __builtin_fpclassify (FP_NAN, FP_INFINITE, \ |
962 | FP_NORMAL, FP_SUBNORMAL, FP_ZERO, x) | |
68337808 | 963 | # else |
b4e75104 | 964 | # define fpclassify(x) __MATH_TG ((x), __fpclassify, (x)) |
68337808 | 965 | # endif |
377a515b UD |
966 | |
967 | /* Return nonzero value if sign of X is negative. */ | |
4997e8f3 | 968 | # if __GNUC_PREREQ (6,0) || __glibc_clang_prereq (3,3) |
fcee5905 | 969 | # define signbit(x) __builtin_signbit (x) |
386e1c26 RN |
970 | # elif defined __cplusplus |
971 | /* In C++ mode, __MATH_TG cannot be used, because it relies on | |
972 | __builtin_types_compatible_p, which is a C-only builtin. | |
973 | The check for __cplusplus allows the use of the builtin instead of | |
974 | __MATH_TG. This is provided for libstdc++, only to let its configure | |
975 | test work. No further use of this definition of signbit is expected | |
976 | in C++ mode, since libstdc++ provides its own version of signbit | |
977 | in cmath (which undefines signbit). */ | |
978 | # define signbit(x) __builtin_signbitl (x) | |
fcee5905 | 979 | # elif __GNUC_PREREQ (4,0) |
b4e75104 | 980 | # define signbit(x) __MATH_TG ((x), __builtin_signbit, (x)) |
68337808 | 981 | # else |
b4e75104 | 982 | # define signbit(x) __MATH_TG ((x), __signbit, (x)) |
68337808 | 983 | # endif |
377a515b UD |
984 | |
985 | /* Return nonzero value if X is not +-Inf or NaN. */ | |
4997e8f3 AZ |
986 | # if (__GNUC_PREREQ (4,4) && !defined __SUPPORT_SNAN__) \ |
987 | || __glibc_clang_prereq (2,8) | |
8df4e219 | 988 | # define isfinite(x) __builtin_isfinite (x) |
68337808 | 989 | # else |
b4e75104 | 990 | # define isfinite(x) __MATH_TG ((x), __finite, (x)) |
68337808 | 991 | # endif |
377a515b UD |
992 | |
993 | /* Return nonzero value if X is neither zero, subnormal, Inf, nor NaN. */ | |
4997e8f3 AZ |
994 | # if (__GNUC_PREREQ (4,4) && !defined __SUPPORT_SNAN__) \ |
995 | || __glibc_clang_prereq (2,8) | |
8df4e219 WD |
996 | # define isnormal(x) __builtin_isnormal (x) |
997 | # else | |
998 | # define isnormal(x) (fpclassify (x) == FP_NORMAL) | |
999 | # endif | |
377a515b UD |
1000 | |
1001 | /* Return nonzero value if X is a NaN. We could use `fpclassify' but | |
1002 | we already have this functions `__isnan' and it is faster. */ | |
4997e8f3 AZ |
1003 | # if (__GNUC_PREREQ (4,4) && !defined __SUPPORT_SNAN__) \ |
1004 | || __glibc_clang_prereq (2,8) | |
8df4e219 | 1005 | # define isnan(x) __builtin_isnan (x) |
68337808 | 1006 | # else |
b4e75104 | 1007 | # define isnan(x) __MATH_TG ((x), __isnan, (x)) |
68337808 | 1008 | # endif |
28f540f4 | 1009 | |
0e012e87 | 1010 | /* Return nonzero value if X is positive or negative infinity. */ |
fcee5905 | 1011 | # if __HAVE_DISTINCT_FLOAT128 && !__GNUC_PREREQ (7,0) \ |
47a67213 GG |
1012 | && !defined __SUPPORT_SNAN__ && !defined __cplusplus |
1013 | /* Since __builtin_isinf_sign is broken for float128 before GCC 7.0, | |
1014 | use the helper function, __isinff128, with older compilers. This is | |
1015 | only provided for C mode, because in C++ mode, GCC has no support | |
1016 | for __builtin_types_compatible_p (and when in C++ mode, this macro is | |
1017 | not used anyway, because libstdc++ headers undefine it). */ | |
fcee5905 PM |
1018 | # define isinf(x) \ |
1019 | (__builtin_types_compatible_p (__typeof (x), _Float128) \ | |
1020 | ? __isinff128 (x) : __builtin_isinf_sign (x)) | |
4997e8f3 AZ |
1021 | # elif (__GNUC_PREREQ (4,4) && !defined __SUPPORT_SNAN__) \ |
1022 | || __glibc_clang_prereq (3,7) | |
8df4e219 | 1023 | # define isinf(x) __builtin_isinf_sign (x) |
68337808 | 1024 | # else |
b4e75104 | 1025 | # define isinf(x) __MATH_TG ((x), __isinf, (x)) |
68337808 | 1026 | # endif |
bfce746a | 1027 | |
12b64309 UD |
1028 | /* Bitmasks for the math_errhandling macro. */ |
1029 | # define MATH_ERRNO 1 /* errno set by math functions. */ | |
1030 | # define MATH_ERREXCEPT 2 /* Exceptions raised by math functions. */ | |
1031 | ||
3c7d0312 WD |
1032 | /* By default all math functions support both errno and exception handling |
1033 | (except for soft floating point implementations which may only support | |
1034 | errno handling). If errno handling is disabled, exceptions are still | |
1035 | supported by GLIBC. Set math_errhandling to 0 with -ffast-math (this is | |
1036 | nonconforming but it is more useful than leaving it undefined). */ | |
1037 | # ifdef __FAST_MATH__ | |
1038 | # define math_errhandling 0 | |
1039 | # elif defined __NO_MATH_ERRNO__ | |
1040 | # define math_errhandling (MATH_ERREXCEPT) | |
1041 | # else | |
7b943af6 UD |
1042 | # define math_errhandling (MATH_ERRNO | MATH_ERREXCEPT) |
1043 | # endif | |
1044 | ||
ec751a23 | 1045 | #endif /* Use ISO C99. */ |
377a515b | 1046 | |
0175c9e9 | 1047 | #if __GLIBC_USE (IEC_60559_BFP_EXT_C2X) |
29cb9293 JM |
1048 | # include <bits/iscanonical.h> |
1049 | ||
57267616 | 1050 | /* Return nonzero value if X is a signaling NaN. */ |
a16e8bc0 GG |
1051 | # ifndef __cplusplus |
1052 | # define issignaling(x) __MATH_TG ((x), __issignaling, (x)) | |
1053 | # else | |
1054 | /* In C++ mode, __MATH_TG cannot be used, because it relies on | |
1055 | __builtin_types_compatible_p, which is a C-only builtin. On the | |
1056 | other hand, overloading provides the means to distinguish between | |
1057 | the floating-point types. The overloading resolution will match | |
1058 | the correct parameter (regardless of type qualifiers (i.e.: const | |
aa0235df | 1059 | and volatile)). */ |
a16e8bc0 GG |
1060 | extern "C++" { |
1061 | inline int issignaling (float __val) { return __issignalingf (__val); } | |
1062 | inline int issignaling (double __val) { return __issignaling (__val); } | |
3d7b66f6 GG |
1063 | inline int |
1064 | issignaling (long double __val) | |
1065 | { | |
1066 | # ifdef __NO_LONG_DOUBLE_MATH | |
1067 | return __issignaling (__val); | |
1068 | # else | |
1069 | return __issignalingl (__val); | |
1070 | # endif | |
1071 | } | |
5db7d705 TMQMF |
1072 | # if __HAVE_FLOAT128_UNLIKE_LDBL |
1073 | /* When using an IEEE 128-bit long double, _Float128 is defined as long double | |
1074 | in C++. */ | |
a16e8bc0 GG |
1075 | inline int issignaling (_Float128 __val) { return __issignalingf128 (__val); } |
1076 | # endif | |
1077 | } /* extern C++ */ | |
1078 | # endif | |
d942e95c JM |
1079 | |
1080 | /* Return nonzero value if X is subnormal. */ | |
1081 | # define issubnormal(x) (fpclassify (x) == FP_SUBNORMAL) | |
bb8081f5 JM |
1082 | |
1083 | /* Return nonzero value if X is zero. */ | |
b3918c44 FW |
1084 | # ifndef __cplusplus |
1085 | # ifdef __SUPPORT_SNAN__ | |
1086 | # define iszero(x) (fpclassify (x) == FP_ZERO) | |
1087 | # else | |
1088 | # define iszero(x) (((__typeof (x)) (x)) == 0) | |
1089 | # endif | |
1090 | # else /* __cplusplus */ | |
e37208ce | 1091 | extern "C++" { |
42496114 GG |
1092 | # ifdef __SUPPORT_SNAN__ |
1093 | inline int | |
1094 | iszero (float __val) | |
1095 | { | |
1096 | return __fpclassifyf (__val) == FP_ZERO; | |
1097 | } | |
1098 | inline int | |
1099 | iszero (double __val) | |
1100 | { | |
1101 | return __fpclassify (__val) == FP_ZERO; | |
1102 | } | |
1103 | inline int | |
1104 | iszero (long double __val) | |
1105 | { | |
1106 | # ifdef __NO_LONG_DOUBLE_MATH | |
1107 | return __fpclassify (__val) == FP_ZERO; | |
1108 | # else | |
1109 | return __fpclassifyl (__val) == FP_ZERO; | |
1110 | # endif | |
1111 | } | |
5db7d705 TMQMF |
1112 | # if __HAVE_FLOAT128_UNLIKE_LDBL |
1113 | /* When using an IEEE 128-bit long double, _Float128 is defined as long double | |
1114 | in C++. */ | |
42496114 GG |
1115 | inline int |
1116 | iszero (_Float128 __val) | |
1117 | { | |
1118 | return __fpclassifyf128 (__val) == FP_ZERO; | |
1119 | } | |
1120 | # endif | |
1121 | # else | |
b3918c44 FW |
1122 | template <class __T> inline bool |
1123 | iszero (__T __val) | |
1124 | { | |
b3918c44 | 1125 | return __val == 0; |
b3918c44 | 1126 | } |
42496114 | 1127 | # endif |
e37208ce | 1128 | } /* extern C++ */ |
b3918c44 | 1129 | # endif /* __cplusplus */ |
bf91be88 | 1130 | #endif /* Use IEC_60559_BFP_EXT. */ |
57267616 | 1131 | |
813378e9 | 1132 | #ifdef __USE_XOPEN |
377a515b | 1133 | /* X/Open wants another strange constant. */ |
813378e9 JM |
1134 | # define MAXFLOAT 3.40282347e+38F |
1135 | #endif | |
28f540f4 | 1136 | |
28f540f4 | 1137 | |
28f540f4 | 1138 | /* Some useful constants. */ |
498afc54 | 1139 | #if defined __USE_MISC || defined __USE_XOPEN |
0a614877 UD |
1140 | # define M_E 2.7182818284590452354 /* e */ |
1141 | # define M_LOG2E 1.4426950408889634074 /* log_2 e */ | |
1142 | # define M_LOG10E 0.43429448190325182765 /* log_10 e */ | |
1143 | # define M_LN2 0.69314718055994530942 /* log_e 2 */ | |
1144 | # define M_LN10 2.30258509299404568402 /* log_e 10 */ | |
1145 | # define M_PI 3.14159265358979323846 /* pi */ | |
1146 | # define M_PI_2 1.57079632679489661923 /* pi/2 */ | |
1147 | # define M_PI_4 0.78539816339744830962 /* pi/4 */ | |
1148 | # define M_1_PI 0.31830988618379067154 /* 1/pi */ | |
1149 | # define M_2_PI 0.63661977236758134308 /* 2/pi */ | |
1150 | # define M_2_SQRTPI 1.12837916709551257390 /* 2/sqrt(pi) */ | |
1151 | # define M_SQRT2 1.41421356237309504880 /* sqrt(2) */ | |
1152 | # define M_SQRT1_2 0.70710678118654752440 /* 1/sqrt(2) */ | |
714a562f UD |
1153 | #endif |
1154 | ||
0a614877 UD |
1155 | /* The above constants are not adequate for computation using `long double's. |
1156 | Therefore we provide as an extension constants with similar names as a | |
9a24f906 | 1157 | GNU extension. Provide enough digits for the 128-bit IEEE quad. */ |
0a614877 | 1158 | #ifdef __USE_GNU |
2d10d547 JM |
1159 | # define M_El 2.718281828459045235360287471352662498L /* e */ |
1160 | # define M_LOG2El 1.442695040888963407359924681001892137L /* log_2 e */ | |
1161 | # define M_LOG10El 0.434294481903251827651128918916605082L /* log_10 e */ | |
1162 | # define M_LN2l 0.693147180559945309417232121458176568L /* log_e 2 */ | |
1163 | # define M_LN10l 2.302585092994045684017991454684364208L /* log_e 10 */ | |
1164 | # define M_PIl 3.141592653589793238462643383279502884L /* pi */ | |
1165 | # define M_PI_2l 1.570796326794896619231321691639751442L /* pi/2 */ | |
1166 | # define M_PI_4l 0.785398163397448309615660845819875721L /* pi/4 */ | |
1167 | # define M_1_PIl 0.318309886183790671537767526745028724L /* 1/pi */ | |
1168 | # define M_2_PIl 0.636619772367581343075535053490057448L /* 2/pi */ | |
1169 | # define M_2_SQRTPIl 1.128379167095512573896158903121545172L /* 2/sqrt(pi) */ | |
1170 | # define M_SQRT2l 1.414213562373095048801688724209698079L /* sqrt(2) */ | |
1171 | # define M_SQRT1_2l 0.707106781186547524400844362104849039L /* 1/sqrt(2) */ | |
0a614877 | 1172 | #endif |
710f7bab | 1173 | |
ce12269f JM |
1174 | #if __HAVE_FLOAT16 && defined __USE_GNU |
1175 | # define M_Ef16 __f16 (2.718281828459045235360287471352662498) /* e */ | |
1176 | # define M_LOG2Ef16 __f16 (1.442695040888963407359924681001892137) /* log_2 e */ | |
1177 | # define M_LOG10Ef16 __f16 (0.434294481903251827651128918916605082) /* log_10 e */ | |
1178 | # define M_LN2f16 __f16 (0.693147180559945309417232121458176568) /* log_e 2 */ | |
1179 | # define M_LN10f16 __f16 (2.302585092994045684017991454684364208) /* log_e 10 */ | |
1180 | # define M_PIf16 __f16 (3.141592653589793238462643383279502884) /* pi */ | |
1181 | # define M_PI_2f16 __f16 (1.570796326794896619231321691639751442) /* pi/2 */ | |
1182 | # define M_PI_4f16 __f16 (0.785398163397448309615660845819875721) /* pi/4 */ | |
1183 | # define M_1_PIf16 __f16 (0.318309886183790671537767526745028724) /* 1/pi */ | |
1184 | # define M_2_PIf16 __f16 (0.636619772367581343075535053490057448) /* 2/pi */ | |
1185 | # define M_2_SQRTPIf16 __f16 (1.128379167095512573896158903121545172) /* 2/sqrt(pi) */ | |
1186 | # define M_SQRT2f16 __f16 (1.414213562373095048801688724209698079) /* sqrt(2) */ | |
1187 | # define M_SQRT1_2f16 __f16 (0.707106781186547524400844362104849039) /* 1/sqrt(2) */ | |
1188 | #endif | |
1189 | ||
1190 | #if __HAVE_FLOAT32 && defined __USE_GNU | |
1191 | # define M_Ef32 __f32 (2.718281828459045235360287471352662498) /* e */ | |
1192 | # define M_LOG2Ef32 __f32 (1.442695040888963407359924681001892137) /* log_2 e */ | |
1193 | # define M_LOG10Ef32 __f32 (0.434294481903251827651128918916605082) /* log_10 e */ | |
1194 | # define M_LN2f32 __f32 (0.693147180559945309417232121458176568) /* log_e 2 */ | |
1195 | # define M_LN10f32 __f32 (2.302585092994045684017991454684364208) /* log_e 10 */ | |
1196 | # define M_PIf32 __f32 (3.141592653589793238462643383279502884) /* pi */ | |
1197 | # define M_PI_2f32 __f32 (1.570796326794896619231321691639751442) /* pi/2 */ | |
1198 | # define M_PI_4f32 __f32 (0.785398163397448309615660845819875721) /* pi/4 */ | |
1199 | # define M_1_PIf32 __f32 (0.318309886183790671537767526745028724) /* 1/pi */ | |
1200 | # define M_2_PIf32 __f32 (0.636619772367581343075535053490057448) /* 2/pi */ | |
1201 | # define M_2_SQRTPIf32 __f32 (1.128379167095512573896158903121545172) /* 2/sqrt(pi) */ | |
1202 | # define M_SQRT2f32 __f32 (1.414213562373095048801688724209698079) /* sqrt(2) */ | |
1203 | # define M_SQRT1_2f32 __f32 (0.707106781186547524400844362104849039) /* 1/sqrt(2) */ | |
1204 | #endif | |
1205 | ||
1206 | #if __HAVE_FLOAT64 && defined __USE_GNU | |
1207 | # define M_Ef64 __f64 (2.718281828459045235360287471352662498) /* e */ | |
1208 | # define M_LOG2Ef64 __f64 (1.442695040888963407359924681001892137) /* log_2 e */ | |
1209 | # define M_LOG10Ef64 __f64 (0.434294481903251827651128918916605082) /* log_10 e */ | |
1210 | # define M_LN2f64 __f64 (0.693147180559945309417232121458176568) /* log_e 2 */ | |
1211 | # define M_LN10f64 __f64 (2.302585092994045684017991454684364208) /* log_e 10 */ | |
1212 | # define M_PIf64 __f64 (3.141592653589793238462643383279502884) /* pi */ | |
1213 | # define M_PI_2f64 __f64 (1.570796326794896619231321691639751442) /* pi/2 */ | |
1214 | # define M_PI_4f64 __f64 (0.785398163397448309615660845819875721) /* pi/4 */ | |
1215 | # define M_1_PIf64 __f64 (0.318309886183790671537767526745028724) /* 1/pi */ | |
1216 | # define M_2_PIf64 __f64 (0.636619772367581343075535053490057448) /* 2/pi */ | |
1217 | # define M_2_SQRTPIf64 __f64 (1.128379167095512573896158903121545172) /* 2/sqrt(pi) */ | |
1218 | # define M_SQRT2f64 __f64 (1.414213562373095048801688724209698079) /* sqrt(2) */ | |
1219 | # define M_SQRT1_2f64 __f64 (0.707106781186547524400844362104849039) /* 1/sqrt(2) */ | |
1220 | #endif | |
1221 | ||
fcee5905 PM |
1222 | #if __HAVE_FLOAT128 && defined __USE_GNU |
1223 | # define M_Ef128 __f128 (2.718281828459045235360287471352662498) /* e */ | |
1224 | # define M_LOG2Ef128 __f128 (1.442695040888963407359924681001892137) /* log_2 e */ | |
1225 | # define M_LOG10Ef128 __f128 (0.434294481903251827651128918916605082) /* log_10 e */ | |
1226 | # define M_LN2f128 __f128 (0.693147180559945309417232121458176568) /* log_e 2 */ | |
1227 | # define M_LN10f128 __f128 (2.302585092994045684017991454684364208) /* log_e 10 */ | |
1228 | # define M_PIf128 __f128 (3.141592653589793238462643383279502884) /* pi */ | |
1229 | # define M_PI_2f128 __f128 (1.570796326794896619231321691639751442) /* pi/2 */ | |
1230 | # define M_PI_4f128 __f128 (0.785398163397448309615660845819875721) /* pi/4 */ | |
1231 | # define M_1_PIf128 __f128 (0.318309886183790671537767526745028724) /* 1/pi */ | |
1232 | # define M_2_PIf128 __f128 (0.636619772367581343075535053490057448) /* 2/pi */ | |
1233 | # define M_2_SQRTPIf128 __f128 (1.128379167095512573896158903121545172) /* 2/sqrt(pi) */ | |
1234 | # define M_SQRT2f128 __f128 (1.414213562373095048801688724209698079) /* sqrt(2) */ | |
1235 | # define M_SQRT1_2f128 __f128 (0.707106781186547524400844362104849039) /* 1/sqrt(2) */ | |
1236 | #endif | |
28f540f4 | 1237 | |
ce12269f JM |
1238 | #if __HAVE_FLOAT32X && defined __USE_GNU |
1239 | # define M_Ef32x __f32x (2.718281828459045235360287471352662498) /* e */ | |
1240 | # define M_LOG2Ef32x __f32x (1.442695040888963407359924681001892137) /* log_2 e */ | |
1241 | # define M_LOG10Ef32x __f32x (0.434294481903251827651128918916605082) /* log_10 e */ | |
1242 | # define M_LN2f32x __f32x (0.693147180559945309417232121458176568) /* log_e 2 */ | |
1243 | # define M_LN10f32x __f32x (2.302585092994045684017991454684364208) /* log_e 10 */ | |
1244 | # define M_PIf32x __f32x (3.141592653589793238462643383279502884) /* pi */ | |
1245 | # define M_PI_2f32x __f32x (1.570796326794896619231321691639751442) /* pi/2 */ | |
1246 | # define M_PI_4f32x __f32x (0.785398163397448309615660845819875721) /* pi/4 */ | |
1247 | # define M_1_PIf32x __f32x (0.318309886183790671537767526745028724) /* 1/pi */ | |
1248 | # define M_2_PIf32x __f32x (0.636619772367581343075535053490057448) /* 2/pi */ | |
1249 | # define M_2_SQRTPIf32x __f32x (1.128379167095512573896158903121545172) /* 2/sqrt(pi) */ | |
1250 | # define M_SQRT2f32x __f32x (1.414213562373095048801688724209698079) /* sqrt(2) */ | |
1251 | # define M_SQRT1_2f32x __f32x (0.707106781186547524400844362104849039) /* 1/sqrt(2) */ | |
1252 | #endif | |
1253 | ||
1254 | #if __HAVE_FLOAT64X && defined __USE_GNU | |
1255 | # define M_Ef64x __f64x (2.718281828459045235360287471352662498) /* e */ | |
1256 | # define M_LOG2Ef64x __f64x (1.442695040888963407359924681001892137) /* log_2 e */ | |
1257 | # define M_LOG10Ef64x __f64x (0.434294481903251827651128918916605082) /* log_10 e */ | |
1258 | # define M_LN2f64x __f64x (0.693147180559945309417232121458176568) /* log_e 2 */ | |
1259 | # define M_LN10f64x __f64x (2.302585092994045684017991454684364208) /* log_e 10 */ | |
1260 | # define M_PIf64x __f64x (3.141592653589793238462643383279502884) /* pi */ | |
1261 | # define M_PI_2f64x __f64x (1.570796326794896619231321691639751442) /* pi/2 */ | |
1262 | # define M_PI_4f64x __f64x (0.785398163397448309615660845819875721) /* pi/4 */ | |
1263 | # define M_1_PIf64x __f64x (0.318309886183790671537767526745028724) /* 1/pi */ | |
1264 | # define M_2_PIf64x __f64x (0.636619772367581343075535053490057448) /* 2/pi */ | |
1265 | # define M_2_SQRTPIf64x __f64x (1.128379167095512573896158903121545172) /* 2/sqrt(pi) */ | |
1266 | # define M_SQRT2f64x __f64x (1.414213562373095048801688724209698079) /* sqrt(2) */ | |
1267 | # define M_SQRT1_2f64x __f64x (0.707106781186547524400844362104849039) /* 1/sqrt(2) */ | |
1268 | #endif | |
1269 | ||
1270 | #if __HAVE_FLOAT128X && defined __USE_GNU | |
1271 | # error "M_* values needed for _Float128x" | |
1272 | #endif | |
1273 | ||
1e6d0723 WD |
1274 | #ifdef __USE_ISOC99 |
1275 | # if __GNUC_PREREQ (3, 1) | |
f4c024d1 UD |
1276 | /* ISO C99 defines some macros to compare number while taking care for |
1277 | unordered numbers. Many FPUs provide special instructions to support | |
1278 | these operations. Generic support in GCC for these as builtins went | |
1e6d0723 WD |
1279 | in 2.97, but not all cpus added their patterns until 3.1. Therefore |
1280 | we enable the builtins from 3.1 onwards and use a generic implementation | |
1281 | othwerwise. */ | |
1282 | # define isgreater(x, y) __builtin_isgreater(x, y) | |
1283 | # define isgreaterequal(x, y) __builtin_isgreaterequal(x, y) | |
1284 | # define isless(x, y) __builtin_isless(x, y) | |
1285 | # define islessequal(x, y) __builtin_islessequal(x, y) | |
1286 | # define islessgreater(x, y) __builtin_islessgreater(x, y) | |
1287 | # define isunordered(x, y) __builtin_isunordered(x, y) | |
1288 | # else | |
1289 | # define isgreater(x, y) \ | |
1290 | (__extension__ ({ __typeof__ (x) __x = (x); __typeof__ (y) __y = (y); \ | |
1291 | !isunordered (__x, __y) && __x > __y; })) | |
1292 | # define isgreaterequal(x, y) \ | |
1293 | (__extension__ ({ __typeof__ (x) __x = (x); __typeof__ (y) __y = (y); \ | |
1294 | !isunordered (__x, __y) && __x >= __y; })) | |
1295 | # define isless(x, y) \ | |
1296 | (__extension__ ({ __typeof__ (x) __x = (x); __typeof__ (y) __y = (y); \ | |
1297 | !isunordered (__x, __y) && __x < __y; })) | |
1298 | # define islessequal(x, y) \ | |
1299 | (__extension__ ({ __typeof__ (x) __x = (x); __typeof__ (y) __y = (y); \ | |
1300 | !isunordered (__x, __y) && __x <= __y; })) | |
1301 | # define islessgreater(x, y) \ | |
1302 | (__extension__ ({ __typeof__ (x) __x = (x); __typeof__ (y) __y = (y); \ | |
1303 | !isunordered (__x, __y) && __x != __y; })) | |
1304 | /* isunordered must always check both operands first for signaling NaNs. */ | |
1305 | # define isunordered(x, y) \ | |
1306 | (__extension__ ({ __typeof__ (x) __u = (x); __typeof__ (y) __v = (y); \ | |
1307 | __u != __v && (__u != __u || __v != __v); })) | |
1308 | # endif | |
f4c024d1 UD |
1309 | #endif |
1310 | ||
0175c9e9 | 1311 | #if __GLIBC_USE (IEC_60559_BFP_EXT_C2X) |
b4e75104 JM |
1312 | /* An expression whose type has the widest of the evaluation formats |
1313 | of X and Y (which are of floating-point types). */ | |
1314 | # if __FLT_EVAL_METHOD__ == 2 || __FLT_EVAL_METHOD__ > 64 | |
1315 | # define __MATH_EVAL_FMT2(x, y) ((x) + (y) + 0.0L) | |
1316 | # elif __FLT_EVAL_METHOD__ == 1 || __FLT_EVAL_METHOD__ > 32 | |
1317 | # define __MATH_EVAL_FMT2(x, y) ((x) + (y) + 0.0) | |
540af6e2 JM |
1318 | # elif __FLT_EVAL_METHOD__ == 0 || __FLT_EVAL_METHOD__ == 32 |
1319 | # define __MATH_EVAL_FMT2(x, y) ((x) + (y) + 0.0f) | |
1e7c8fcc | 1320 | # else |
b4e75104 | 1321 | # define __MATH_EVAL_FMT2(x, y) ((x) + (y)) |
1e7c8fcc | 1322 | # endif |
b4e75104 JM |
1323 | |
1324 | /* Return X == Y but raising "invalid" and setting errno if X or Y is | |
1325 | a NaN. */ | |
c85e54ac GG |
1326 | # if !defined __cplusplus || (__cplusplus < 201103L && !defined __GNUC__) |
1327 | # define iseqsig(x, y) \ | |
1328 | __MATH_TG (__MATH_EVAL_FMT2 (x, y), __iseqsig, ((x), (y))) | |
1329 | # else | |
1330 | /* In C++ mode, __MATH_TG cannot be used, because it relies on | |
1331 | __builtin_types_compatible_p, which is a C-only builtin. Moreover, | |
1332 | the comparison macros from ISO C take two floating-point arguments, | |
1333 | which need not have the same type. Choosing what underlying function | |
1334 | to call requires evaluating the formats of the arguments, then | |
1335 | selecting which is wider. The macro __MATH_EVAL_FMT2 provides this | |
1336 | information, however, only the type of the macro expansion is | |
1337 | relevant (actually evaluating the expression would be incorrect). | |
1338 | Thus, the type is used as a template parameter for __iseqsig_type, | |
1339 | which calls the appropriate underlying function. */ | |
1340 | extern "C++" { | |
1341 | template<typename> struct __iseqsig_type; | |
1342 | ||
1343 | template<> struct __iseqsig_type<float> | |
1344 | { | |
1345 | static int __call (float __x, float __y) throw () | |
1346 | { | |
1347 | return __iseqsigf (__x, __y); | |
1348 | } | |
1349 | }; | |
1350 | ||
1351 | template<> struct __iseqsig_type<double> | |
1352 | { | |
1353 | static int __call (double __x, double __y) throw () | |
1354 | { | |
1355 | return __iseqsig (__x, __y); | |
1356 | } | |
1357 | }; | |
1358 | ||
1359 | template<> struct __iseqsig_type<long double> | |
1360 | { | |
fb0e10b8 | 1361 | static int __call (long double __x, long double __y) throw () |
c85e54ac GG |
1362 | { |
1363 | # ifndef __NO_LONG_DOUBLE_MATH | |
1364 | return __iseqsigl (__x, __y); | |
1365 | # else | |
1366 | return __iseqsig (__x, __y); | |
1367 | # endif | |
1368 | } | |
1369 | }; | |
1370 | ||
5db7d705 TMQMF |
1371 | # if __HAVE_FLOAT128_UNLIKE_LDBL |
1372 | /* When using an IEEE 128-bit long double, _Float128 is defined as long double | |
1373 | in C++. */ | |
c85e54ac GG |
1374 | template<> struct __iseqsig_type<_Float128> |
1375 | { | |
1376 | static int __call (_Float128 __x, _Float128 __y) throw () | |
1377 | { | |
1378 | return __iseqsigf128 (__x, __y); | |
1379 | } | |
1380 | }; | |
1381 | # endif | |
1382 | ||
1383 | template<typename _T1, typename _T2> | |
1384 | inline int | |
1385 | iseqsig (_T1 __x, _T2 __y) throw () | |
1386 | { | |
1387 | # if __cplusplus >= 201103L | |
1388 | typedef decltype (__MATH_EVAL_FMT2 (__x, __y)) _T3; | |
1389 | # else | |
1390 | typedef __typeof (__MATH_EVAL_FMT2 (__x, __y)) _T3; | |
1391 | # endif | |
1392 | return __iseqsig_type<_T3>::__call (__x, __y); | |
1393 | } | |
1394 | ||
1395 | } /* extern "C++" */ | |
1396 | # endif /* __cplusplus */ | |
1397 | ||
1e7c8fcc JM |
1398 | #endif |
1399 | ||
4d585333 RM |
1400 | __END_DECLS |
1401 | ||
1402 | ||
28f540f4 | 1403 | #endif /* math.h */ |