x86_64: Fix build with RTLD_PRIVATE_ERRNO defined to 1
[glibc.git] / math / math.h
blob2e2696854bd1fc0e0e95b4c289071ec11ffa3e15
1 /* Declarations for math functions.
2 Copyright (C) 1991-2018 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
5 The GNU C Library is free software; you can redistribute it and/or
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.
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
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <http://www.gnu.org/licenses/>. */
20 * ISO C99 Standard: 7.12 Mathematics <math.h>
23 #ifndef _MATH_H
24 #define _MATH_H 1
26 #define __GLIBC_INTERNAL_STARTING_HEADER_IMPLEMENTATION
27 #include <bits/libc-header-start.h>
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
34 __BEGIN_DECLS
36 /* Get definitions of __intmax_t and __uintmax_t. */
37 #include <bits/types.h>
39 /* Get machine-dependent vector math functions declarations. */
40 #include <bits/math-vector.h>
42 /* Gather machine dependent type support. */
43 #include <bits/floatn.h>
45 /* Value returned on overflow. With IEEE 754 floating point, this is
46 +Infinity, otherwise the largest representable positive value. */
47 #if __GNUC_PREREQ (3, 3)
48 # define HUGE_VAL (__builtin_huge_val ())
49 #else
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. */
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
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
75 #if __HAVE_FLOAT128 && __GLIBC_USE (IEC_60559_TYPES_EXT)
76 # define HUGE_VAL_F128 (__builtin_huge_valf128 ())
77 #endif
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
88 #ifdef __USE_ISOC99
89 /* IEEE positive infinity. */
90 # if __GNUC_PREREQ (3, 3)
91 # define INFINITY (__builtin_inff ())
92 # else
93 # define INFINITY HUGE_VALF
94 # endif
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
105 #endif /* __USE_ISOC99 */
107 #if __GLIBC_USE (IEC_60559_BFP_EXT)
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
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
124 #if __HAVE_FLOAT128 && __GLIBC_USE (IEC_60559_TYPES_EXT)
125 # define SNANF128 (__builtin_nansf128 (""))
126 #endif
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
137 /* Get __GLIBC_FLT_EVAL_METHOD. */
138 #include <bits/flt-eval-method.h>
140 #ifdef __USE_ISOC99
141 /* Define the following typedefs.
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
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
180 /* Define macros for the return values of ilogb and llogb, based on
181 __FP_LOGB0_IS_MIN and __FP_LOGBNAN_IS_MIN.
183 FP_ILOGB0 Expands to a value returned by `ilogb (0.0)'.
184 FP_ILOGBNAN Expands to a value returned by `ilogb (NAN)'.
185 FP_LLOGB0 Expands to a value returned by `llogb (0.0)'.
186 FP_LLOGBNAN Expands to a value returned by `llogb (NAN)'.
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
203 #if __GLIBC_USE (IEC_60559_BFP_EXT)
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
221 /* Get the architecture specific values describing the floating-point
222 evaluation. The following symbols will get defined:
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.
233 #include <bits/fp-fast.h>
235 #if __GLIBC_USE (IEC_60559_BFP_EXT)
236 /* Rounding direction macros for fromfp functions. */
237 enum
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,
255 #endif
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',
260 and can declare the float versions `namef' and `__namef'. */
262 #define __SIMD_DECL(function) __CONCAT (__DECL_SIMD_, function)
264 #define __MATHCALL_VEC(function, suffix, args) \
265 __SIMD_DECL (__MATH_PRECNAME (function, suffix)) \
266 __MATHCALL (function, suffix, args)
268 #define __MATHDECL_VEC(type, function,suffix, args) \
269 __SIMD_DECL (__MATH_PRECNAME (function, suffix)) \
270 __MATHDECL(type, function,suffix, args)
272 #define __MATHCALL(function,suffix, args) \
273 __MATHDECL (_Mdouble_,function,suffix, args)
274 #define __MATHDECL(type, function,suffix, args) \
275 __MATHDECL_1(type, function,suffix, args); \
276 __MATHDECL_1(type, __CONCAT(__,function),suffix, args)
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)
282 #define __MATHDECL_1(type, function,suffix, args) \
283 extern type __MATH_PRECNAME(function,suffix) args __THROW
285 #define _Mdouble_ double
286 #define __MATH_PRECNAME(name,r) __CONCAT(name,r)
287 #define __MATH_DECLARING_DOUBLE 1
288 #define __MATH_DECLARING_FLOATN 0
289 #include <bits/mathcalls-helper-functions.h>
290 #include <bits/mathcalls.h>
291 #undef _Mdouble_
292 #undef __MATH_PRECNAME
293 #undef __MATH_DECLARING_DOUBLE
294 #undef __MATH_DECLARING_FLOATN
296 #ifdef __USE_ISOC99
299 /* Include the file of declarations again, this time using `float'
300 instead of `double' and appending f to each function name. */
302 # define _Mdouble_ float
303 # define __MATH_PRECNAME(name,r) name##f##r
304 # define __MATH_DECLARING_DOUBLE 0
305 # define __MATH_DECLARING_FLOATN 0
306 # include <bits/mathcalls-helper-functions.h>
307 # include <bits/mathcalls.h>
308 # undef _Mdouble_
309 # undef __MATH_PRECNAME
310 # undef __MATH_DECLARING_DOUBLE
311 # undef __MATH_DECLARING_FLOATN
313 # if !(defined __NO_LONG_DOUBLE_MATH && defined _LIBC) \
314 || defined __LDBL_COMPAT \
315 || defined _LIBC_TEST
316 # ifdef __LDBL_COMPAT
318 # ifdef __USE_ISOC99
319 extern float __nldbl_nexttowardf (float __x, long double __y)
320 __THROW __attribute__ ((__const__));
321 # ifdef __REDIRECT_NTH
322 extern float __REDIRECT_NTH (nexttowardf, (float __x, long double __y),
323 __nldbl_nexttowardf)
324 __attribute__ ((__const__));
325 extern double __REDIRECT_NTH (nexttoward, (double __x, long double __y),
326 nextafter) __attribute__ ((__const__));
327 extern long double __REDIRECT_NTH (nexttowardl,
328 (long double __x, long double __y),
329 nextafter) __attribute__ ((__const__));
330 # endif
331 # endif
333 # undef __MATHDECL_1
334 # define __MATHDECL_2(type, function,suffix, args, alias) \
335 extern type __REDIRECT_NTH(__MATH_PRECNAME(function,suffix), \
336 args, alias)
337 # define __MATHDECL_1(type, function,suffix, args) \
338 __MATHDECL_2(type, function,suffix, args, __CONCAT(function,suffix))
339 # endif
341 /* Include the file of declarations again, this time using `long double'
342 instead of `double' and appending l to each function name. */
344 # define _Mdouble_ long double
345 # define __MATH_PRECNAME(name,r) name##l##r
346 # define __MATH_DECLARING_DOUBLE 0
347 # define __MATH_DECLARING_FLOATN 0
348 # define __MATH_DECLARE_LDOUBLE 1
349 # include <bits/mathcalls-helper-functions.h>
350 # include <bits/mathcalls.h>
351 # undef _Mdouble_
352 # undef __MATH_PRECNAME
353 # undef __MATH_DECLARING_DOUBLE
354 # undef __MATH_DECLARING_FLOATN
356 # endif /* !(__NO_LONG_DOUBLE_MATH && _LIBC) || __LDBL_COMPAT */
358 #endif /* Use ISO C99. */
360 /* Include the file of declarations for _FloatN and _FloatNx
361 types. */
363 #if __HAVE_DISTINCT_FLOAT16 || (__HAVE_FLOAT16 && !defined _LIBC)
364 # define _Mdouble_ _Float16
365 # define __MATH_PRECNAME(name,r) name##f16##r
366 # define __MATH_DECLARING_DOUBLE 0
367 # define __MATH_DECLARING_FLOATN 1
368 # if __HAVE_DISTINCT_FLOAT16
369 # include <bits/mathcalls-helper-functions.h>
370 # endif
371 # if __GLIBC_USE (IEC_60559_TYPES_EXT)
372 # include <bits/mathcalls.h>
373 # endif
374 # undef _Mdouble_
375 # undef __MATH_PRECNAME
376 # undef __MATH_DECLARING_DOUBLE
377 # undef __MATH_DECLARING_FLOATN
378 #endif /* __HAVE_DISTINCT_FLOAT16 || (__HAVE_FLOAT16 && !_LIBC). */
380 #if __HAVE_DISTINCT_FLOAT32 || (__HAVE_FLOAT32 && !defined _LIBC)
381 # define _Mdouble_ _Float32
382 # define __MATH_PRECNAME(name,r) name##f32##r
383 # define __MATH_DECLARING_DOUBLE 0
384 # define __MATH_DECLARING_FLOATN 1
385 # if __HAVE_DISTINCT_FLOAT32
386 # include <bits/mathcalls-helper-functions.h>
387 # endif
388 # if __GLIBC_USE (IEC_60559_TYPES_EXT)
389 # include <bits/mathcalls.h>
390 # endif
391 # undef _Mdouble_
392 # undef __MATH_PRECNAME
393 # undef __MATH_DECLARING_DOUBLE
394 # undef __MATH_DECLARING_FLOATN
395 #endif /* __HAVE_DISTINCT_FLOAT32 || (__HAVE_FLOAT32 && !_LIBC). */
397 #if __HAVE_DISTINCT_FLOAT64 || (__HAVE_FLOAT64 && !defined _LIBC)
398 # define _Mdouble_ _Float64
399 # define __MATH_PRECNAME(name,r) name##f64##r
400 # define __MATH_DECLARING_DOUBLE 0
401 # define __MATH_DECLARING_FLOATN 1
402 # if __HAVE_DISTINCT_FLOAT64
403 # include <bits/mathcalls-helper-functions.h>
404 # endif
405 # if __GLIBC_USE (IEC_60559_TYPES_EXT)
406 # include <bits/mathcalls.h>
407 # endif
408 # undef _Mdouble_
409 # undef __MATH_PRECNAME
410 # undef __MATH_DECLARING_DOUBLE
411 # undef __MATH_DECLARING_FLOATN
412 #endif /* __HAVE_DISTINCT_FLOAT64 || (__HAVE_FLOAT64 && !_LIBC). */
414 #if __HAVE_DISTINCT_FLOAT128 || (__HAVE_FLOAT128 && !defined _LIBC)
415 # define _Mdouble_ _Float128
416 # define __MATH_PRECNAME(name,r) name##f128##r
417 # define __MATH_DECLARING_DOUBLE 0
418 # define __MATH_DECLARING_FLOATN 1
419 # if __HAVE_DISTINCT_FLOAT128
420 # include <bits/mathcalls-helper-functions.h>
421 # endif
422 # if __GLIBC_USE (IEC_60559_TYPES_EXT)
423 # include <bits/mathcalls.h>
424 # endif
425 # undef _Mdouble_
426 # undef __MATH_PRECNAME
427 # undef __MATH_DECLARING_DOUBLE
428 # undef __MATH_DECLARING_FLOATN
429 #endif /* __HAVE_DISTINCT_FLOAT128 || (__HAVE_FLOAT128 && !_LIBC). */
431 #if __HAVE_DISTINCT_FLOAT32X || (__HAVE_FLOAT32X && !defined _LIBC)
432 # define _Mdouble_ _Float32x
433 # define __MATH_PRECNAME(name,r) name##f32x##r
434 # define __MATH_DECLARING_DOUBLE 0
435 # define __MATH_DECLARING_FLOATN 1
436 # if __HAVE_DISTINCT_FLOAT32X
437 # include <bits/mathcalls-helper-functions.h>
438 # endif
439 # if __GLIBC_USE (IEC_60559_TYPES_EXT)
440 # include <bits/mathcalls.h>
441 # endif
442 # undef _Mdouble_
443 # undef __MATH_PRECNAME
444 # undef __MATH_DECLARING_DOUBLE
445 # undef __MATH_DECLARING_FLOATN
446 #endif /* __HAVE_DISTINCT_FLOAT32X || (__HAVE_FLOAT32X && !_LIBC). */
448 #if __HAVE_DISTINCT_FLOAT64X || (__HAVE_FLOAT64X && !defined _LIBC)
449 # define _Mdouble_ _Float64x
450 # define __MATH_PRECNAME(name,r) name##f64x##r
451 # define __MATH_DECLARING_DOUBLE 0
452 # define __MATH_DECLARING_FLOATN 1
453 # if __HAVE_DISTINCT_FLOAT64X
454 # include <bits/mathcalls-helper-functions.h>
455 # endif
456 # if __GLIBC_USE (IEC_60559_TYPES_EXT)
457 # include <bits/mathcalls.h>
458 # endif
459 # undef _Mdouble_
460 # undef __MATH_PRECNAME
461 # undef __MATH_DECLARING_DOUBLE
462 # undef __MATH_DECLARING_FLOATN
463 #endif /* __HAVE_DISTINCT_FLOAT64X || (__HAVE_FLOAT64X && !_LIBC). */
465 #if __HAVE_DISTINCT_FLOAT128X || (__HAVE_FLOAT128X && !defined _LIBC)
466 # define _Mdouble_ _Float128x
467 # define __MATH_PRECNAME(name,r) name##f128x##r
468 # define __MATH_DECLARING_DOUBLE 0
469 # define __MATH_DECLARING_FLOATN 1
470 # if __HAVE_DISTINCT_FLOAT128X
471 # include <bits/mathcalls-helper-functions.h>
472 # endif
473 # if __GLIBC_USE (IEC_60559_TYPES_EXT)
474 # include <bits/mathcalls.h>
475 # endif
476 # undef _Mdouble_
477 # undef __MATH_PRECNAME
478 # undef __MATH_DECLARING_DOUBLE
479 # undef __MATH_DECLARING_FLOATN
480 #endif /* __HAVE_DISTINCT_FLOAT128X || (__HAVE_FLOAT128X && !_LIBC). */
482 #undef __MATHDECL_1
483 #undef __MATHDECL
484 #undef __MATHCALL
486 /* Declare functions returning a narrower type. */
487 #define __MATHCALL_NARROW_ARGS_1 (_Marg_ __x)
488 #define __MATHCALL_NARROW_ARGS_2 (_Marg_ __x, _Marg_ __y)
489 #define __MATHCALL_NARROW_ARGS_3 (_Marg_ __x, _Marg_ __y, _Marg_ __z)
490 #define __MATHCALL_NARROW_NORMAL(func, nargs) \
491 extern _Mret_ func __MATHCALL_NARROW_ARGS_ ## nargs __THROW
492 #define __MATHCALL_NARROW_REDIR(func, redir, nargs) \
493 extern _Mret_ __REDIRECT_NTH (func, __MATHCALL_NARROW_ARGS_ ## nargs, \
494 redir)
495 #define __MATHCALL_NARROW(func, redir, nargs) \
496 __MATHCALL_NARROW_NORMAL (func, nargs)
498 #if __GLIBC_USE (IEC_60559_BFP_EXT)
500 # define _Mret_ float
501 # define _Marg_ double
502 # define __MATHCALL_NAME(name) f ## name
503 # include <bits/mathcalls-narrow.h>
504 # undef _Mret_
505 # undef _Marg_
506 # undef __MATHCALL_NAME
508 # define _Mret_ float
509 # define _Marg_ long double
510 # define __MATHCALL_NAME(name) f ## name ## l
511 # ifdef __LDBL_COMPAT
512 # define __MATHCALL_REDIR_NAME(name) f ## name
513 # undef __MATHCALL_NARROW
514 # define __MATHCALL_NARROW(func, redir, nargs) \
515 __MATHCALL_NARROW_REDIR (func, redir, nargs)
516 # endif
517 # include <bits/mathcalls-narrow.h>
518 # undef _Mret_
519 # undef _Marg_
520 # undef __MATHCALL_NAME
521 # ifdef __LDBL_COMPAT
522 # undef __MATHCALL_REDIR_NAME
523 # undef __MATHCALL_NARROW
524 # define __MATHCALL_NARROW(func, redir, nargs) \
525 __MATHCALL_NARROW_NORMAL (func, nargs)
526 # endif
528 # define _Mret_ double
529 # define _Marg_ long double
530 # define __MATHCALL_NAME(name) d ## name ## l
531 # ifdef __LDBL_COMPAT
532 # define __MATHCALL_REDIR_NAME(name) __nldbl_d ## name ## l
533 # undef __MATHCALL_NARROW
534 # define __MATHCALL_NARROW(func, redir, nargs) \
535 __MATHCALL_NARROW_REDIR (func, redir, nargs)
536 # endif
537 # include <bits/mathcalls-narrow.h>
538 # undef _Mret_
539 # undef _Marg_
540 # undef __MATHCALL_NAME
541 # ifdef __LDBL_COMPAT
542 # undef __MATHCALL_REDIR_NAME
543 # undef __MATHCALL_NARROW
544 # define __MATHCALL_NARROW(func, redir, nargs) \
545 __MATHCALL_NARROW_NORMAL (func, nargs)
546 # endif
548 #endif
550 #if __GLIBC_USE (IEC_60559_TYPES_EXT)
552 # if __HAVE_FLOAT16 && __HAVE_FLOAT32
553 # define _Mret_ _Float16
554 # define _Marg_ _Float32
555 # define __MATHCALL_NAME(name) f16 ## name ## f32
556 # include <bits/mathcalls-narrow.h>
557 # undef _Mret_
558 # undef _Marg_
559 # undef __MATHCALL_NAME
560 # endif
562 # if __HAVE_FLOAT16 && __HAVE_FLOAT32X
563 # define _Mret_ _Float16
564 # define _Marg_ _Float32x
565 # define __MATHCALL_NAME(name) f16 ## name ## f32x
566 # include <bits/mathcalls-narrow.h>
567 # undef _Mret_
568 # undef _Marg_
569 # undef __MATHCALL_NAME
570 # endif
572 # if __HAVE_FLOAT16 && __HAVE_FLOAT64
573 # define _Mret_ _Float16
574 # define _Marg_ _Float64
575 # define __MATHCALL_NAME(name) f16 ## name ## f64
576 # include <bits/mathcalls-narrow.h>
577 # undef _Mret_
578 # undef _Marg_
579 # undef __MATHCALL_NAME
580 # endif
582 # if __HAVE_FLOAT16 && __HAVE_FLOAT64X
583 # define _Mret_ _Float16
584 # define _Marg_ _Float64x
585 # define __MATHCALL_NAME(name) f16 ## name ## f64x
586 # include <bits/mathcalls-narrow.h>
587 # undef _Mret_
588 # undef _Marg_
589 # undef __MATHCALL_NAME
590 # endif
592 # if __HAVE_FLOAT16 && __HAVE_FLOAT128
593 # define _Mret_ _Float16
594 # define _Marg_ _Float128
595 # define __MATHCALL_NAME(name) f16 ## name ## f128
596 # include <bits/mathcalls-narrow.h>
597 # undef _Mret_
598 # undef _Marg_
599 # undef __MATHCALL_NAME
600 # endif
602 # if __HAVE_FLOAT16 && __HAVE_FLOAT128X
603 # define _Mret_ _Float16
604 # define _Marg_ _Float128x
605 # define __MATHCALL_NAME(name) f16 ## name ## f128x
606 # include <bits/mathcalls-narrow.h>
607 # undef _Mret_
608 # undef _Marg_
609 # undef __MATHCALL_NAME
610 # endif
612 # if __HAVE_FLOAT32 && __HAVE_FLOAT32X
613 # define _Mret_ _Float32
614 # define _Marg_ _Float32x
615 # define __MATHCALL_NAME(name) f32 ## name ## f32x
616 # include <bits/mathcalls-narrow.h>
617 # undef _Mret_
618 # undef _Marg_
619 # undef __MATHCALL_NAME
620 # endif
622 # if __HAVE_FLOAT32 && __HAVE_FLOAT64
623 # define _Mret_ _Float32
624 # define _Marg_ _Float64
625 # define __MATHCALL_NAME(name) f32 ## name ## f64
626 # include <bits/mathcalls-narrow.h>
627 # undef _Mret_
628 # undef _Marg_
629 # undef __MATHCALL_NAME
630 # endif
632 # if __HAVE_FLOAT32 && __HAVE_FLOAT64X
633 # define _Mret_ _Float32
634 # define _Marg_ _Float64x
635 # define __MATHCALL_NAME(name) f32 ## name ## f64x
636 # include <bits/mathcalls-narrow.h>
637 # undef _Mret_
638 # undef _Marg_
639 # undef __MATHCALL_NAME
640 # endif
642 # if __HAVE_FLOAT32 && __HAVE_FLOAT128
643 # define _Mret_ _Float32
644 # define _Marg_ _Float128
645 # define __MATHCALL_NAME(name) f32 ## name ## f128
646 # include <bits/mathcalls-narrow.h>
647 # undef _Mret_
648 # undef _Marg_
649 # undef __MATHCALL_NAME
650 # endif
652 # if __HAVE_FLOAT32 && __HAVE_FLOAT128X
653 # define _Mret_ _Float32
654 # define _Marg_ _Float128x
655 # define __MATHCALL_NAME(name) f32 ## name ## f128x
656 # include <bits/mathcalls-narrow.h>
657 # undef _Mret_
658 # undef _Marg_
659 # undef __MATHCALL_NAME
660 # endif
662 # if __HAVE_FLOAT32X && __HAVE_FLOAT64
663 # define _Mret_ _Float32x
664 # define _Marg_ _Float64
665 # define __MATHCALL_NAME(name) f32x ## name ## f64
666 # include <bits/mathcalls-narrow.h>
667 # undef _Mret_
668 # undef _Marg_
669 # undef __MATHCALL_NAME
670 # endif
672 # if __HAVE_FLOAT32X && __HAVE_FLOAT64X
673 # define _Mret_ _Float32x
674 # define _Marg_ _Float64x
675 # define __MATHCALL_NAME(name) f32x ## name ## f64x
676 # include <bits/mathcalls-narrow.h>
677 # undef _Mret_
678 # undef _Marg_
679 # undef __MATHCALL_NAME
680 # endif
682 # if __HAVE_FLOAT32X && __HAVE_FLOAT128
683 # define _Mret_ _Float32x
684 # define _Marg_ _Float128
685 # define __MATHCALL_NAME(name) f32x ## name ## f128
686 # include <bits/mathcalls-narrow.h>
687 # undef _Mret_
688 # undef _Marg_
689 # undef __MATHCALL_NAME
690 # endif
692 # if __HAVE_FLOAT32X && __HAVE_FLOAT128X
693 # define _Mret_ _Float32x
694 # define _Marg_ _Float128x
695 # define __MATHCALL_NAME(name) f32x ## name ## f128x
696 # include <bits/mathcalls-narrow.h>
697 # undef _Mret_
698 # undef _Marg_
699 # undef __MATHCALL_NAME
700 # endif
702 # if __HAVE_FLOAT64 && __HAVE_FLOAT64X
703 # define _Mret_ _Float64
704 # define _Marg_ _Float64x
705 # define __MATHCALL_NAME(name) f64 ## name ## f64x
706 # include <bits/mathcalls-narrow.h>
707 # undef _Mret_
708 # undef _Marg_
709 # undef __MATHCALL_NAME
710 # endif
712 # if __HAVE_FLOAT64 && __HAVE_FLOAT128
713 # define _Mret_ _Float64
714 # define _Marg_ _Float128
715 # define __MATHCALL_NAME(name) f64 ## name ## f128
716 # include <bits/mathcalls-narrow.h>
717 # undef _Mret_
718 # undef _Marg_
719 # undef __MATHCALL_NAME
720 # endif
722 # if __HAVE_FLOAT64 && __HAVE_FLOAT128X
723 # define _Mret_ _Float64
724 # define _Marg_ _Float128x
725 # define __MATHCALL_NAME(name) f64 ## name ## f128x
726 # include <bits/mathcalls-narrow.h>
727 # undef _Mret_
728 # undef _Marg_
729 # undef __MATHCALL_NAME
730 # endif
732 # if __HAVE_FLOAT64X && __HAVE_FLOAT128
733 # define _Mret_ _Float64x
734 # define _Marg_ _Float128
735 # define __MATHCALL_NAME(name) f64x ## name ## f128
736 # include <bits/mathcalls-narrow.h>
737 # undef _Mret_
738 # undef _Marg_
739 # undef __MATHCALL_NAME
740 # endif
742 # if __HAVE_FLOAT64X && __HAVE_FLOAT128X
743 # define _Mret_ _Float64x
744 # define _Marg_ _Float128x
745 # define __MATHCALL_NAME(name) f64x ## name ## f128x
746 # include <bits/mathcalls-narrow.h>
747 # undef _Mret_
748 # undef _Marg_
749 # undef __MATHCALL_NAME
750 # endif
752 # if __HAVE_FLOAT128 && __HAVE_FLOAT128X
753 # define _Mret_ _Float128
754 # define _Marg_ _Float128x
755 # define __MATHCALL_NAME(name) f128 ## name ## f128x
756 # include <bits/mathcalls-narrow.h>
757 # undef _Mret_
758 # undef _Marg_
759 # undef __MATHCALL_NAME
760 # endif
762 #endif
764 #undef __MATHCALL_NARROW_ARGS_1
765 #undef __MATHCALL_NARROW_ARGS_2
766 #undef __MATHCALL_NARROW_ARGS_3
767 #undef __MATHCALL_NARROW_NORMAL
768 #undef __MATHCALL_NARROW_REDIR
769 #undef __MATHCALL_NARROW
771 #if defined __USE_MISC || defined __USE_XOPEN
772 /* This variable is used by `gamma' and `lgamma'. */
773 extern int signgam;
774 #endif
776 #if (__HAVE_DISTINCT_FLOAT16 \
777 || __HAVE_DISTINCT_FLOAT32 \
778 || __HAVE_DISTINCT_FLOAT64 \
779 || __HAVE_DISTINCT_FLOAT32X \
780 || __HAVE_DISTINCT_FLOAT64X \
781 || __HAVE_DISTINCT_FLOAT128X)
782 # error "Unsupported _FloatN or _FloatNx types for <math.h>."
783 #endif
785 /* Depending on the type of TG_ARG, call an appropriately suffixed
786 version of FUNC with arguments (including parentheses) ARGS.
787 Suffixed functions may not exist for long double if it has the same
788 format as double, or for other types with the same format as float,
789 double or long double. The behavior is undefined if the argument
790 does not have a real floating type. The definition may use a
791 conditional expression, so all suffixed versions of FUNC must
792 return the same type (FUNC may include a cast if necessary rather
793 than being a single identifier). */
794 #ifdef __NO_LONG_DOUBLE_MATH
795 # if __HAVE_DISTINCT_FLOAT128
796 # error "Distinct _Float128 without distinct long double not supported."
797 # endif
798 # define __MATH_TG(TG_ARG, FUNC, ARGS) \
799 (sizeof (TG_ARG) == sizeof (float) ? FUNC ## f ARGS : FUNC ARGS)
800 #elif __HAVE_DISTINCT_FLOAT128
801 # if __HAVE_GENERIC_SELECTION
802 # if __HAVE_FLOATN_NOT_TYPEDEF && __HAVE_FLOAT32
803 # define __MATH_TG_F32(FUNC, ARGS) _Float32: FUNC ## f ARGS,
804 # else
805 # define __MATH_TG_F32(FUNC, ARGS)
806 # endif
807 # if __HAVE_FLOATN_NOT_TYPEDEF && __HAVE_FLOAT64X
808 # if __HAVE_FLOAT64X_LONG_DOUBLE
809 # define __MATH_TG_F64X(FUNC, ARGS) _Float64x: FUNC ## l ARGS,
810 # else
811 # define __MATH_TG_F64X(FUNC, ARGS) _Float64x: FUNC ## f128 ARGS,
812 # endif
813 # else
814 # define __MATH_TG_F64X(FUNC, ARGS)
815 # endif
816 # define __MATH_TG(TG_ARG, FUNC, ARGS) \
817 _Generic ((TG_ARG), \
818 float: FUNC ## f ARGS, \
819 __MATH_TG_F32 (FUNC, ARGS) \
820 default: FUNC ARGS, \
821 long double: FUNC ## l ARGS, \
822 __MATH_TG_F64X (FUNC, ARGS) \
823 _Float128: FUNC ## f128 ARGS)
824 # else
825 # if __HAVE_FLOATN_NOT_TYPEDEF
826 # error "Non-typedef _FloatN but no _Generic."
827 # endif
828 # define __MATH_TG(TG_ARG, FUNC, ARGS) \
829 __builtin_choose_expr \
830 (__builtin_types_compatible_p (__typeof (TG_ARG), float), \
831 FUNC ## f ARGS, \
832 __builtin_choose_expr \
833 (__builtin_types_compatible_p (__typeof (TG_ARG), double), \
834 FUNC ARGS, \
835 __builtin_choose_expr \
836 (__builtin_types_compatible_p (__typeof (TG_ARG), long double), \
837 FUNC ## l ARGS, \
838 FUNC ## f128 ARGS)))
839 # endif
840 #else
841 # define __MATH_TG(TG_ARG, FUNC, ARGS) \
842 (sizeof (TG_ARG) == sizeof (float) \
843 ? FUNC ## f ARGS \
844 : sizeof (TG_ARG) == sizeof (double) \
845 ? FUNC ARGS \
846 : FUNC ## l ARGS)
847 #endif
849 /* ISO C99 defines some generic macros which work on any data type. */
850 #ifdef __USE_ISOC99
852 /* All floating-point numbers can be put in one of these categories. */
853 enum
855 FP_NAN =
856 # define FP_NAN 0
857 FP_NAN,
858 FP_INFINITE =
859 # define FP_INFINITE 1
860 FP_INFINITE,
861 FP_ZERO =
862 # define FP_ZERO 2
863 FP_ZERO,
864 FP_SUBNORMAL =
865 # define FP_SUBNORMAL 3
866 FP_SUBNORMAL,
867 FP_NORMAL =
868 # define FP_NORMAL 4
869 FP_NORMAL
872 /* GCC bug 66462 means we cannot use the math builtins with -fsignaling-nan,
873 so disable builtins if this is enabled. When fixed in a newer GCC,
874 the __SUPPORT_SNAN__ check may be skipped for those versions. */
876 /* Return number of classification appropriate for X. */
877 # if __GNUC_PREREQ (4,4) && !defined __SUPPORT_SNAN__ \
878 && (!defined __OPTIMIZE_SIZE__ || defined __cplusplus)
879 /* The check for __cplusplus allows the use of the builtin, even
880 when optimization for size is on. This is provided for
881 libstdc++, only to let its configure test work when it is built
882 with -Os. No further use of this definition of fpclassify is
883 expected in C++ mode, since libstdc++ provides its own version
884 of fpclassify in cmath (which undefines fpclassify). */
885 # define fpclassify(x) __builtin_fpclassify (FP_NAN, FP_INFINITE, \
886 FP_NORMAL, FP_SUBNORMAL, FP_ZERO, x)
887 # else
888 # define fpclassify(x) __MATH_TG ((x), __fpclassify, (x))
889 # endif
891 /* Return nonzero value if sign of X is negative. */
892 # if __GNUC_PREREQ (6,0)
893 # define signbit(x) __builtin_signbit (x)
894 # elif defined __cplusplus
895 /* In C++ mode, __MATH_TG cannot be used, because it relies on
896 __builtin_types_compatible_p, which is a C-only builtin.
897 The check for __cplusplus allows the use of the builtin instead of
898 __MATH_TG. This is provided for libstdc++, only to let its configure
899 test work. No further use of this definition of signbit is expected
900 in C++ mode, since libstdc++ provides its own version of signbit
901 in cmath (which undefines signbit). */
902 # define signbit(x) __builtin_signbitl (x)
903 # elif __GNUC_PREREQ (4,0)
904 # define signbit(x) __MATH_TG ((x), __builtin_signbit, (x))
905 # else
906 # define signbit(x) __MATH_TG ((x), __signbit, (x))
907 # endif
909 /* Return nonzero value if X is not +-Inf or NaN. */
910 # if __GNUC_PREREQ (4,4) && !defined __SUPPORT_SNAN__
911 # define isfinite(x) __builtin_isfinite (x)
912 # else
913 # define isfinite(x) __MATH_TG ((x), __finite, (x))
914 # endif
916 /* Return nonzero value if X is neither zero, subnormal, Inf, nor NaN. */
917 # if __GNUC_PREREQ (4,4) && !defined __SUPPORT_SNAN__
918 # define isnormal(x) __builtin_isnormal (x)
919 # else
920 # define isnormal(x) (fpclassify (x) == FP_NORMAL)
921 # endif
923 /* Return nonzero value if X is a NaN. We could use `fpclassify' but
924 we already have this functions `__isnan' and it is faster. */
925 # if __GNUC_PREREQ (4,4) && !defined __SUPPORT_SNAN__
926 # define isnan(x) __builtin_isnan (x)
927 # else
928 # define isnan(x) __MATH_TG ((x), __isnan, (x))
929 # endif
931 /* Return nonzero value if X is positive or negative infinity. */
932 # if __HAVE_DISTINCT_FLOAT128 && !__GNUC_PREREQ (7,0) \
933 && !defined __SUPPORT_SNAN__ && !defined __cplusplus
934 /* Since __builtin_isinf_sign is broken for float128 before GCC 7.0,
935 use the helper function, __isinff128, with older compilers. This is
936 only provided for C mode, because in C++ mode, GCC has no support
937 for __builtin_types_compatible_p (and when in C++ mode, this macro is
938 not used anyway, because libstdc++ headers undefine it). */
939 # define isinf(x) \
940 (__builtin_types_compatible_p (__typeof (x), _Float128) \
941 ? __isinff128 (x) : __builtin_isinf_sign (x))
942 # elif __GNUC_PREREQ (4,4) && !defined __SUPPORT_SNAN__
943 # define isinf(x) __builtin_isinf_sign (x)
944 # else
945 # define isinf(x) __MATH_TG ((x), __isinf, (x))
946 # endif
948 /* Bitmasks for the math_errhandling macro. */
949 # define MATH_ERRNO 1 /* errno set by math functions. */
950 # define MATH_ERREXCEPT 2 /* Exceptions raised by math functions. */
952 /* By default all math functions support both errno and exception handling
953 (except for soft floating point implementations which may only support
954 errno handling). If errno handling is disabled, exceptions are still
955 supported by GLIBC. Set math_errhandling to 0 with -ffast-math (this is
956 nonconforming but it is more useful than leaving it undefined). */
957 # ifdef __FAST_MATH__
958 # define math_errhandling 0
959 # elif defined __NO_MATH_ERRNO__
960 # define math_errhandling (MATH_ERREXCEPT)
961 # else
962 # define math_errhandling (MATH_ERRNO | MATH_ERREXCEPT)
963 # endif
965 #endif /* Use ISO C99. */
967 #if __GLIBC_USE (IEC_60559_BFP_EXT)
968 # include <bits/iscanonical.h>
970 /* Return nonzero value if X is a signaling NaN. */
971 # ifndef __cplusplus
972 # define issignaling(x) __MATH_TG ((x), __issignaling, (x))
973 # else
974 /* In C++ mode, __MATH_TG cannot be used, because it relies on
975 __builtin_types_compatible_p, which is a C-only builtin. On the
976 other hand, overloading provides the means to distinguish between
977 the floating-point types. The overloading resolution will match
978 the correct parameter (regardless of type qualifiers (i.e.: const
979 and volatile)). */
980 extern "C++" {
981 inline int issignaling (float __val) { return __issignalingf (__val); }
982 inline int issignaling (double __val) { return __issignaling (__val); }
983 inline int
984 issignaling (long double __val)
986 # ifdef __NO_LONG_DOUBLE_MATH
987 return __issignaling (__val);
988 # else
989 return __issignalingl (__val);
990 # endif
992 # if __HAVE_DISTINCT_FLOAT128
993 inline int issignaling (_Float128 __val) { return __issignalingf128 (__val); }
994 # endif
995 } /* extern C++ */
996 # endif
998 /* Return nonzero value if X is subnormal. */
999 # define issubnormal(x) (fpclassify (x) == FP_SUBNORMAL)
1001 /* Return nonzero value if X is zero. */
1002 # ifndef __cplusplus
1003 # ifdef __SUPPORT_SNAN__
1004 # define iszero(x) (fpclassify (x) == FP_ZERO)
1005 # else
1006 # define iszero(x) (((__typeof (x)) (x)) == 0)
1007 # endif
1008 # else /* __cplusplus */
1009 extern "C++" {
1010 # ifdef __SUPPORT_SNAN__
1011 inline int
1012 iszero (float __val)
1014 return __fpclassifyf (__val) == FP_ZERO;
1016 inline int
1017 iszero (double __val)
1019 return __fpclassify (__val) == FP_ZERO;
1021 inline int
1022 iszero (long double __val)
1024 # ifdef __NO_LONG_DOUBLE_MATH
1025 return __fpclassify (__val) == FP_ZERO;
1026 # else
1027 return __fpclassifyl (__val) == FP_ZERO;
1028 # endif
1030 # if __HAVE_DISTINCT_FLOAT128
1031 inline int
1032 iszero (_Float128 __val)
1034 return __fpclassifyf128 (__val) == FP_ZERO;
1036 # endif
1037 # else
1038 template <class __T> inline bool
1039 iszero (__T __val)
1041 return __val == 0;
1043 # endif
1044 } /* extern C++ */
1045 # endif /* __cplusplus */
1046 #endif /* Use IEC_60559_BFP_EXT. */
1048 #ifdef __USE_XOPEN
1049 /* X/Open wants another strange constant. */
1050 # define MAXFLOAT 3.40282347e+38F
1051 #endif
1054 /* Some useful constants. */
1055 #if defined __USE_MISC || defined __USE_XOPEN
1056 # define M_E 2.7182818284590452354 /* e */
1057 # define M_LOG2E 1.4426950408889634074 /* log_2 e */
1058 # define M_LOG10E 0.43429448190325182765 /* log_10 e */
1059 # define M_LN2 0.69314718055994530942 /* log_e 2 */
1060 # define M_LN10 2.30258509299404568402 /* log_e 10 */
1061 # define M_PI 3.14159265358979323846 /* pi */
1062 # define M_PI_2 1.57079632679489661923 /* pi/2 */
1063 # define M_PI_4 0.78539816339744830962 /* pi/4 */
1064 # define M_1_PI 0.31830988618379067154 /* 1/pi */
1065 # define M_2_PI 0.63661977236758134308 /* 2/pi */
1066 # define M_2_SQRTPI 1.12837916709551257390 /* 2/sqrt(pi) */
1067 # define M_SQRT2 1.41421356237309504880 /* sqrt(2) */
1068 # define M_SQRT1_2 0.70710678118654752440 /* 1/sqrt(2) */
1069 #endif
1071 /* The above constants are not adequate for computation using `long double's.
1072 Therefore we provide as an extension constants with similar names as a
1073 GNU extension. Provide enough digits for the 128-bit IEEE quad. */
1074 #ifdef __USE_GNU
1075 # define M_El 2.718281828459045235360287471352662498L /* e */
1076 # define M_LOG2El 1.442695040888963407359924681001892137L /* log_2 e */
1077 # define M_LOG10El 0.434294481903251827651128918916605082L /* log_10 e */
1078 # define M_LN2l 0.693147180559945309417232121458176568L /* log_e 2 */
1079 # define M_LN10l 2.302585092994045684017991454684364208L /* log_e 10 */
1080 # define M_PIl 3.141592653589793238462643383279502884L /* pi */
1081 # define M_PI_2l 1.570796326794896619231321691639751442L /* pi/2 */
1082 # define M_PI_4l 0.785398163397448309615660845819875721L /* pi/4 */
1083 # define M_1_PIl 0.318309886183790671537767526745028724L /* 1/pi */
1084 # define M_2_PIl 0.636619772367581343075535053490057448L /* 2/pi */
1085 # define M_2_SQRTPIl 1.128379167095512573896158903121545172L /* 2/sqrt(pi) */
1086 # define M_SQRT2l 1.414213562373095048801688724209698079L /* sqrt(2) */
1087 # define M_SQRT1_2l 0.707106781186547524400844362104849039L /* 1/sqrt(2) */
1088 #endif
1090 #if __HAVE_FLOAT16 && defined __USE_GNU
1091 # define M_Ef16 __f16 (2.718281828459045235360287471352662498) /* e */
1092 # define M_LOG2Ef16 __f16 (1.442695040888963407359924681001892137) /* log_2 e */
1093 # define M_LOG10Ef16 __f16 (0.434294481903251827651128918916605082) /* log_10 e */
1094 # define M_LN2f16 __f16 (0.693147180559945309417232121458176568) /* log_e 2 */
1095 # define M_LN10f16 __f16 (2.302585092994045684017991454684364208) /* log_e 10 */
1096 # define M_PIf16 __f16 (3.141592653589793238462643383279502884) /* pi */
1097 # define M_PI_2f16 __f16 (1.570796326794896619231321691639751442) /* pi/2 */
1098 # define M_PI_4f16 __f16 (0.785398163397448309615660845819875721) /* pi/4 */
1099 # define M_1_PIf16 __f16 (0.318309886183790671537767526745028724) /* 1/pi */
1100 # define M_2_PIf16 __f16 (0.636619772367581343075535053490057448) /* 2/pi */
1101 # define M_2_SQRTPIf16 __f16 (1.128379167095512573896158903121545172) /* 2/sqrt(pi) */
1102 # define M_SQRT2f16 __f16 (1.414213562373095048801688724209698079) /* sqrt(2) */
1103 # define M_SQRT1_2f16 __f16 (0.707106781186547524400844362104849039) /* 1/sqrt(2) */
1104 #endif
1106 #if __HAVE_FLOAT32 && defined __USE_GNU
1107 # define M_Ef32 __f32 (2.718281828459045235360287471352662498) /* e */
1108 # define M_LOG2Ef32 __f32 (1.442695040888963407359924681001892137) /* log_2 e */
1109 # define M_LOG10Ef32 __f32 (0.434294481903251827651128918916605082) /* log_10 e */
1110 # define M_LN2f32 __f32 (0.693147180559945309417232121458176568) /* log_e 2 */
1111 # define M_LN10f32 __f32 (2.302585092994045684017991454684364208) /* log_e 10 */
1112 # define M_PIf32 __f32 (3.141592653589793238462643383279502884) /* pi */
1113 # define M_PI_2f32 __f32 (1.570796326794896619231321691639751442) /* pi/2 */
1114 # define M_PI_4f32 __f32 (0.785398163397448309615660845819875721) /* pi/4 */
1115 # define M_1_PIf32 __f32 (0.318309886183790671537767526745028724) /* 1/pi */
1116 # define M_2_PIf32 __f32 (0.636619772367581343075535053490057448) /* 2/pi */
1117 # define M_2_SQRTPIf32 __f32 (1.128379167095512573896158903121545172) /* 2/sqrt(pi) */
1118 # define M_SQRT2f32 __f32 (1.414213562373095048801688724209698079) /* sqrt(2) */
1119 # define M_SQRT1_2f32 __f32 (0.707106781186547524400844362104849039) /* 1/sqrt(2) */
1120 #endif
1122 #if __HAVE_FLOAT64 && defined __USE_GNU
1123 # define M_Ef64 __f64 (2.718281828459045235360287471352662498) /* e */
1124 # define M_LOG2Ef64 __f64 (1.442695040888963407359924681001892137) /* log_2 e */
1125 # define M_LOG10Ef64 __f64 (0.434294481903251827651128918916605082) /* log_10 e */
1126 # define M_LN2f64 __f64 (0.693147180559945309417232121458176568) /* log_e 2 */
1127 # define M_LN10f64 __f64 (2.302585092994045684017991454684364208) /* log_e 10 */
1128 # define M_PIf64 __f64 (3.141592653589793238462643383279502884) /* pi */
1129 # define M_PI_2f64 __f64 (1.570796326794896619231321691639751442) /* pi/2 */
1130 # define M_PI_4f64 __f64 (0.785398163397448309615660845819875721) /* pi/4 */
1131 # define M_1_PIf64 __f64 (0.318309886183790671537767526745028724) /* 1/pi */
1132 # define M_2_PIf64 __f64 (0.636619772367581343075535053490057448) /* 2/pi */
1133 # define M_2_SQRTPIf64 __f64 (1.128379167095512573896158903121545172) /* 2/sqrt(pi) */
1134 # define M_SQRT2f64 __f64 (1.414213562373095048801688724209698079) /* sqrt(2) */
1135 # define M_SQRT1_2f64 __f64 (0.707106781186547524400844362104849039) /* 1/sqrt(2) */
1136 #endif
1138 #if __HAVE_FLOAT128 && defined __USE_GNU
1139 # define M_Ef128 __f128 (2.718281828459045235360287471352662498) /* e */
1140 # define M_LOG2Ef128 __f128 (1.442695040888963407359924681001892137) /* log_2 e */
1141 # define M_LOG10Ef128 __f128 (0.434294481903251827651128918916605082) /* log_10 e */
1142 # define M_LN2f128 __f128 (0.693147180559945309417232121458176568) /* log_e 2 */
1143 # define M_LN10f128 __f128 (2.302585092994045684017991454684364208) /* log_e 10 */
1144 # define M_PIf128 __f128 (3.141592653589793238462643383279502884) /* pi */
1145 # define M_PI_2f128 __f128 (1.570796326794896619231321691639751442) /* pi/2 */
1146 # define M_PI_4f128 __f128 (0.785398163397448309615660845819875721) /* pi/4 */
1147 # define M_1_PIf128 __f128 (0.318309886183790671537767526745028724) /* 1/pi */
1148 # define M_2_PIf128 __f128 (0.636619772367581343075535053490057448) /* 2/pi */
1149 # define M_2_SQRTPIf128 __f128 (1.128379167095512573896158903121545172) /* 2/sqrt(pi) */
1150 # define M_SQRT2f128 __f128 (1.414213562373095048801688724209698079) /* sqrt(2) */
1151 # define M_SQRT1_2f128 __f128 (0.707106781186547524400844362104849039) /* 1/sqrt(2) */
1152 #endif
1154 #if __HAVE_FLOAT32X && defined __USE_GNU
1155 # define M_Ef32x __f32x (2.718281828459045235360287471352662498) /* e */
1156 # define M_LOG2Ef32x __f32x (1.442695040888963407359924681001892137) /* log_2 e */
1157 # define M_LOG10Ef32x __f32x (0.434294481903251827651128918916605082) /* log_10 e */
1158 # define M_LN2f32x __f32x (0.693147180559945309417232121458176568) /* log_e 2 */
1159 # define M_LN10f32x __f32x (2.302585092994045684017991454684364208) /* log_e 10 */
1160 # define M_PIf32x __f32x (3.141592653589793238462643383279502884) /* pi */
1161 # define M_PI_2f32x __f32x (1.570796326794896619231321691639751442) /* pi/2 */
1162 # define M_PI_4f32x __f32x (0.785398163397448309615660845819875721) /* pi/4 */
1163 # define M_1_PIf32x __f32x (0.318309886183790671537767526745028724) /* 1/pi */
1164 # define M_2_PIf32x __f32x (0.636619772367581343075535053490057448) /* 2/pi */
1165 # define M_2_SQRTPIf32x __f32x (1.128379167095512573896158903121545172) /* 2/sqrt(pi) */
1166 # define M_SQRT2f32x __f32x (1.414213562373095048801688724209698079) /* sqrt(2) */
1167 # define M_SQRT1_2f32x __f32x (0.707106781186547524400844362104849039) /* 1/sqrt(2) */
1168 #endif
1170 #if __HAVE_FLOAT64X && defined __USE_GNU
1171 # define M_Ef64x __f64x (2.718281828459045235360287471352662498) /* e */
1172 # define M_LOG2Ef64x __f64x (1.442695040888963407359924681001892137) /* log_2 e */
1173 # define M_LOG10Ef64x __f64x (0.434294481903251827651128918916605082) /* log_10 e */
1174 # define M_LN2f64x __f64x (0.693147180559945309417232121458176568) /* log_e 2 */
1175 # define M_LN10f64x __f64x (2.302585092994045684017991454684364208) /* log_e 10 */
1176 # define M_PIf64x __f64x (3.141592653589793238462643383279502884) /* pi */
1177 # define M_PI_2f64x __f64x (1.570796326794896619231321691639751442) /* pi/2 */
1178 # define M_PI_4f64x __f64x (0.785398163397448309615660845819875721) /* pi/4 */
1179 # define M_1_PIf64x __f64x (0.318309886183790671537767526745028724) /* 1/pi */
1180 # define M_2_PIf64x __f64x (0.636619772367581343075535053490057448) /* 2/pi */
1181 # define M_2_SQRTPIf64x __f64x (1.128379167095512573896158903121545172) /* 2/sqrt(pi) */
1182 # define M_SQRT2f64x __f64x (1.414213562373095048801688724209698079) /* sqrt(2) */
1183 # define M_SQRT1_2f64x __f64x (0.707106781186547524400844362104849039) /* 1/sqrt(2) */
1184 #endif
1186 #if __HAVE_FLOAT128X && defined __USE_GNU
1187 # error "M_* values needed for _Float128x"
1188 #endif
1190 /* When compiling in strict ISO C compatible mode we must not use the
1191 inline functions since they, among other things, do not set the
1192 `errno' variable correctly. */
1193 #if defined __STRICT_ANSI__ && !defined __NO_MATH_INLINES
1194 # define __NO_MATH_INLINES 1
1195 #endif
1197 #ifdef __USE_ISOC99
1198 # if __GNUC_PREREQ (3, 1)
1199 /* ISO C99 defines some macros to compare number while taking care for
1200 unordered numbers. Many FPUs provide special instructions to support
1201 these operations. Generic support in GCC for these as builtins went
1202 in 2.97, but not all cpus added their patterns until 3.1. Therefore
1203 we enable the builtins from 3.1 onwards and use a generic implementation
1204 othwerwise. */
1205 # define isgreater(x, y) __builtin_isgreater(x, y)
1206 # define isgreaterequal(x, y) __builtin_isgreaterequal(x, y)
1207 # define isless(x, y) __builtin_isless(x, y)
1208 # define islessequal(x, y) __builtin_islessequal(x, y)
1209 # define islessgreater(x, y) __builtin_islessgreater(x, y)
1210 # define isunordered(x, y) __builtin_isunordered(x, y)
1211 # else
1212 # define isgreater(x, y) \
1213 (__extension__ ({ __typeof__ (x) __x = (x); __typeof__ (y) __y = (y); \
1214 !isunordered (__x, __y) && __x > __y; }))
1215 # define isgreaterequal(x, y) \
1216 (__extension__ ({ __typeof__ (x) __x = (x); __typeof__ (y) __y = (y); \
1217 !isunordered (__x, __y) && __x >= __y; }))
1218 # define isless(x, y) \
1219 (__extension__ ({ __typeof__ (x) __x = (x); __typeof__ (y) __y = (y); \
1220 !isunordered (__x, __y) && __x < __y; }))
1221 # define islessequal(x, y) \
1222 (__extension__ ({ __typeof__ (x) __x = (x); __typeof__ (y) __y = (y); \
1223 !isunordered (__x, __y) && __x <= __y; }))
1224 # define islessgreater(x, y) \
1225 (__extension__ ({ __typeof__ (x) __x = (x); __typeof__ (y) __y = (y); \
1226 !isunordered (__x, __y) && __x != __y; }))
1227 /* isunordered must always check both operands first for signaling NaNs. */
1228 # define isunordered(x, y) \
1229 (__extension__ ({ __typeof__ (x) __u = (x); __typeof__ (y) __v = (y); \
1230 __u != __v && (__u != __u || __v != __v); }))
1231 # endif
1232 #endif
1234 /* Get machine-dependent inline versions (if there are any). */
1235 #ifdef __USE_EXTERN_INLINES
1236 # include <bits/mathinline.h>
1237 #endif
1239 /* Define special entry points to use when the compiler got told to
1240 only expect finite results. */
1241 #if defined __FINITE_MATH_ONLY__ && __FINITE_MATH_ONLY__ > 0
1243 /* Include bits/math-finite.h for double. */
1244 # define _Mdouble_ double
1245 # define __MATH_DECLARING_DOUBLE 1
1246 # define __MATH_DECLARING_FLOATN 0
1247 # define __REDIRFROM_X(function, reentrant) \
1248 function ## reentrant
1249 # define __REDIRTO_X(function, reentrant) \
1250 __ ## function ## reentrant ## _finite
1251 # include <bits/math-finite.h>
1252 # undef _Mdouble_
1253 # undef __MATH_DECLARING_DOUBLE
1254 # undef __MATH_DECLARING_FLOATN
1255 # undef __REDIRFROM_X
1256 # undef __REDIRTO_X
1258 /* When __USE_ISOC99 is defined, include math-finite for float and
1259 long double, as well. */
1260 # ifdef __USE_ISOC99
1262 /* Include bits/math-finite.h for float. */
1263 # define _Mdouble_ float
1264 # define __MATH_DECLARING_DOUBLE 0
1265 # define __MATH_DECLARING_FLOATN 0
1266 # define __REDIRFROM_X(function, reentrant) \
1267 function ## f ## reentrant
1268 # define __REDIRTO_X(function, reentrant) \
1269 __ ## function ## f ## reentrant ## _finite
1270 # include <bits/math-finite.h>
1271 # undef _Mdouble_
1272 # undef __MATH_DECLARING_DOUBLE
1273 # undef __MATH_DECLARING_FLOATN
1274 # undef __REDIRFROM_X
1275 # undef __REDIRTO_X
1277 /* Include bits/math-finite.h for long double. */
1278 # ifdef __MATH_DECLARE_LDOUBLE
1279 # define _Mdouble_ long double
1280 # define __MATH_DECLARING_DOUBLE 0
1281 # define __MATH_DECLARING_FLOATN 0
1282 # define __REDIRFROM_X(function, reentrant) \
1283 function ## l ## reentrant
1284 # ifdef __NO_LONG_DOUBLE_MATH
1285 # define __REDIRTO_X(function, reentrant) \
1286 __ ## function ## reentrant ## _finite
1287 # else
1288 # define __REDIRTO_X(function, reentrant) \
1289 __ ## function ## l ## reentrant ## _finite
1290 # endif
1291 # include <bits/math-finite.h>
1292 # undef _Mdouble_
1293 # undef __MATH_DECLARING_DOUBLE
1294 # undef __MATH_DECLARING_FLOATN
1295 # undef __REDIRFROM_X
1296 # undef __REDIRTO_X
1297 # endif
1299 # endif /* __USE_ISOC99. */
1301 /* Include bits/math-finite.h for _FloatN and _FloatNx. */
1303 # if (__HAVE_DISTINCT_FLOAT16 || (__HAVE_FLOAT16 && !defined _LIBC)) \
1304 && __GLIBC_USE (IEC_60559_TYPES_EXT)
1305 # define _Mdouble_ _Float16
1306 # define __MATH_DECLARING_DOUBLE 0
1307 # define __MATH_DECLARING_FLOATN 1
1308 # define __REDIRFROM_X(function, reentrant) \
1309 function ## f16 ## reentrant
1310 # if __HAVE_DISTINCT_FLOAT16
1311 # define __REDIRTO_X(function, reentrant) \
1312 __ ## function ## f16 ## reentrant ## _finite
1313 # else
1314 # error "non-disinct _Float16"
1315 # endif
1316 # include <bits/math-finite.h>
1317 # undef _Mdouble_
1318 # undef __MATH_DECLARING_DOUBLE
1319 # undef __MATH_DECLARING_FLOATN
1320 # undef __REDIRFROM_X
1321 # undef __REDIRTO_X
1322 # endif
1324 # if (__HAVE_DISTINCT_FLOAT32 || (__HAVE_FLOAT32 && !defined _LIBC)) \
1325 && __GLIBC_USE (IEC_60559_TYPES_EXT)
1326 # define _Mdouble_ _Float32
1327 # define __MATH_DECLARING_DOUBLE 0
1328 # define __MATH_DECLARING_FLOATN 1
1329 # define __REDIRFROM_X(function, reentrant) \
1330 function ## f32 ## reentrant
1331 # if __HAVE_DISTINCT_FLOAT32
1332 # define __REDIRTO_X(function, reentrant) \
1333 __ ## function ## f32 ## reentrant ## _finite
1334 # else
1335 # define __REDIRTO_X(function, reentrant) \
1336 __ ## function ## f ## reentrant ## _finite
1337 # endif
1338 # include <bits/math-finite.h>
1339 # undef _Mdouble_
1340 # undef __MATH_DECLARING_DOUBLE
1341 # undef __MATH_DECLARING_FLOATN
1342 # undef __REDIRFROM_X
1343 # undef __REDIRTO_X
1344 # endif
1346 # if (__HAVE_DISTINCT_FLOAT64 || (__HAVE_FLOAT64 && !defined _LIBC)) \
1347 && __GLIBC_USE (IEC_60559_TYPES_EXT)
1348 # define _Mdouble_ _Float64
1349 # define __MATH_DECLARING_DOUBLE 0
1350 # define __MATH_DECLARING_FLOATN 1
1351 # define __REDIRFROM_X(function, reentrant) \
1352 function ## f64 ## reentrant
1353 # if __HAVE_DISTINCT_FLOAT64
1354 # define __REDIRTO_X(function, reentrant) \
1355 __ ## function ## f64 ## reentrant ## _finite
1356 # else
1357 # define __REDIRTO_X(function, reentrant) \
1358 __ ## function ## reentrant ## _finite
1359 # endif
1360 # include <bits/math-finite.h>
1361 # undef _Mdouble_
1362 # undef __MATH_DECLARING_DOUBLE
1363 # undef __MATH_DECLARING_FLOATN
1364 # undef __REDIRFROM_X
1365 # undef __REDIRTO_X
1366 # endif
1368 # if (__HAVE_DISTINCT_FLOAT128 || (__HAVE_FLOAT128 && !defined _LIBC)) \
1369 && __GLIBC_USE (IEC_60559_TYPES_EXT)
1370 # define _Mdouble_ _Float128
1371 # define __MATH_DECLARING_DOUBLE 0
1372 # define __MATH_DECLARING_FLOATN 1
1373 # define __REDIRFROM_X(function, reentrant) \
1374 function ## f128 ## reentrant
1375 # if __HAVE_DISTINCT_FLOAT128
1376 # define __REDIRTO_X(function, reentrant) \
1377 __ ## function ## f128 ## reentrant ## _finite
1378 # else
1379 # define __REDIRTO_X(function, reentrant) \
1380 __ ## function ## l ## reentrant ## _finite
1381 # endif
1382 # include <bits/math-finite.h>
1383 # undef _Mdouble_
1384 # undef __MATH_DECLARING_DOUBLE
1385 # undef __MATH_DECLARING_FLOATN
1386 # undef __REDIRFROM_X
1387 # undef __REDIRTO_X
1388 # endif
1390 # if (__HAVE_DISTINCT_FLOAT32X || (__HAVE_FLOAT32X && !defined _LIBC)) \
1391 && __GLIBC_USE (IEC_60559_TYPES_EXT)
1392 # define _Mdouble_ _Float32x
1393 # define __MATH_DECLARING_DOUBLE 0
1394 # define __MATH_DECLARING_FLOATN 1
1395 # define __REDIRFROM_X(function, reentrant) \
1396 function ## f32x ## reentrant
1397 # if __HAVE_DISTINCT_FLOAT32X
1398 # define __REDIRTO_X(function, reentrant) \
1399 __ ## function ## f32x ## reentrant ## _finite
1400 # else
1401 # define __REDIRTO_X(function, reentrant) \
1402 __ ## function ## reentrant ## _finite
1403 # endif
1404 # include <bits/math-finite.h>
1405 # undef _Mdouble_
1406 # undef __MATH_DECLARING_DOUBLE
1407 # undef __MATH_DECLARING_FLOATN
1408 # undef __REDIRFROM_X
1409 # undef __REDIRTO_X
1410 # endif
1412 # if (__HAVE_DISTINCT_FLOAT64X || (__HAVE_FLOAT64X && !defined _LIBC)) \
1413 && __GLIBC_USE (IEC_60559_TYPES_EXT)
1414 # define _Mdouble_ _Float64x
1415 # define __MATH_DECLARING_DOUBLE 0
1416 # define __MATH_DECLARING_FLOATN 1
1417 # define __REDIRFROM_X(function, reentrant) \
1418 function ## f64x ## reentrant
1419 # if __HAVE_DISTINCT_FLOAT64X
1420 # define __REDIRTO_X(function, reentrant) \
1421 __ ## function ## f64x ## reentrant ## _finite
1422 # elif __HAVE_FLOAT64X_LONG_DOUBLE
1423 # define __REDIRTO_X(function, reentrant) \
1424 __ ## function ## l ## reentrant ## _finite
1425 # else
1426 # define __REDIRTO_X(function, reentrant) \
1427 __ ## function ## f128 ## reentrant ## _finite
1428 # endif
1429 # include <bits/math-finite.h>
1430 # undef _Mdouble_
1431 # undef __MATH_DECLARING_DOUBLE
1432 # undef __MATH_DECLARING_FLOATN
1433 # undef __REDIRFROM_X
1434 # undef __REDIRTO_X
1435 # endif
1437 # if (__HAVE_DISTINCT_FLOAT128X || (__HAVE_FLOAT128X && !defined _LIBC)) \
1438 && __GLIBC_USE (IEC_60559_TYPES_EXT)
1439 # define _Mdouble_ _Float128x
1440 # define __MATH_DECLARING_DOUBLE 0
1441 # define __MATH_DECLARING_FLOATN 1
1442 # define __REDIRFROM_X(function, reentrant) \
1443 function ## f128x ## reentrant
1444 # if __HAVE_DISTINCT_FLOAT128X
1445 # define __REDIRTO_X(function, reentrant) \
1446 __ ## function ## f128x ## reentrant ## _finite
1447 # else
1448 # error "non-disinct _Float128x"
1449 # endif
1450 # include <bits/math-finite.h>
1451 # undef _Mdouble_
1452 # undef __MATH_DECLARING_DOUBLE
1453 # undef __MATH_DECLARING_FLOATN
1454 # undef __REDIRFROM_X
1455 # undef __REDIRTO_X
1456 # endif
1458 #endif /* __FINITE_MATH_ONLY__ > 0. */
1460 #if __GLIBC_USE (IEC_60559_BFP_EXT)
1461 /* An expression whose type has the widest of the evaluation formats
1462 of X and Y (which are of floating-point types). */
1463 # if __FLT_EVAL_METHOD__ == 2 || __FLT_EVAL_METHOD__ > 64
1464 # define __MATH_EVAL_FMT2(x, y) ((x) + (y) + 0.0L)
1465 # elif __FLT_EVAL_METHOD__ == 1 || __FLT_EVAL_METHOD__ > 32
1466 # define __MATH_EVAL_FMT2(x, y) ((x) + (y) + 0.0)
1467 # elif __FLT_EVAL_METHOD__ == 0 || __FLT_EVAL_METHOD__ == 32
1468 # define __MATH_EVAL_FMT2(x, y) ((x) + (y) + 0.0f)
1469 # else
1470 # define __MATH_EVAL_FMT2(x, y) ((x) + (y))
1471 # endif
1473 /* Return X == Y but raising "invalid" and setting errno if X or Y is
1474 a NaN. */
1475 # if !defined __cplusplus || (__cplusplus < 201103L && !defined __GNUC__)
1476 # define iseqsig(x, y) \
1477 __MATH_TG (__MATH_EVAL_FMT2 (x, y), __iseqsig, ((x), (y)))
1478 # else
1479 /* In C++ mode, __MATH_TG cannot be used, because it relies on
1480 __builtin_types_compatible_p, which is a C-only builtin. Moreover,
1481 the comparison macros from ISO C take two floating-point arguments,
1482 which need not have the same type. Choosing what underlying function
1483 to call requires evaluating the formats of the arguments, then
1484 selecting which is wider. The macro __MATH_EVAL_FMT2 provides this
1485 information, however, only the type of the macro expansion is
1486 relevant (actually evaluating the expression would be incorrect).
1487 Thus, the type is used as a template parameter for __iseqsig_type,
1488 which calls the appropriate underlying function. */
1489 extern "C++" {
1490 template<typename> struct __iseqsig_type;
1492 template<> struct __iseqsig_type<float>
1494 static int __call (float __x, float __y) throw ()
1496 return __iseqsigf (__x, __y);
1500 template<> struct __iseqsig_type<double>
1502 static int __call (double __x, double __y) throw ()
1504 return __iseqsig (__x, __y);
1508 template<> struct __iseqsig_type<long double>
1510 static int __call (double __x, double __y) throw ()
1512 # ifndef __NO_LONG_DOUBLE_MATH
1513 return __iseqsigl (__x, __y);
1514 # else
1515 return __iseqsig (__x, __y);
1516 # endif
1520 # if __HAVE_DISTINCT_FLOAT128
1521 template<> struct __iseqsig_type<_Float128>
1523 static int __call (_Float128 __x, _Float128 __y) throw ()
1525 return __iseqsigf128 (__x, __y);
1528 # endif
1530 template<typename _T1, typename _T2>
1531 inline int
1532 iseqsig (_T1 __x, _T2 __y) throw ()
1534 # if __cplusplus >= 201103L
1535 typedef decltype (__MATH_EVAL_FMT2 (__x, __y)) _T3;
1536 # else
1537 typedef __typeof (__MATH_EVAL_FMT2 (__x, __y)) _T3;
1538 # endif
1539 return __iseqsig_type<_T3>::__call (__x, __y);
1542 } /* extern "C++" */
1543 # endif /* __cplusplus */
1545 #endif
1547 __END_DECLS
1550 #endif /* math.h */