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