1 /* Declarations for math functions.
2 Copyright (C) 1991-2021 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 <https://www.gnu.org/licenses/>. */
20 * ISO C99 Standard: 7.12 Mathematics <math.h>
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.
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 ())
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
58 # if __GNUC_PREREQ (3, 3)
59 # define HUGE_VALF (__builtin_huge_valf ())
60 # define HUGE_VALL (__builtin_huge_vall ())
62 # define HUGE_VALF 1e10000f
63 # define HUGE_VALL 1e10000L
66 #if __HAVE_FLOAT16 && __GLIBC_USE (IEC_60559_TYPES_EXT)
67 # define HUGE_VAL_F16 (__builtin_huge_valf16 ())
69 #if __HAVE_FLOAT32 && __GLIBC_USE (IEC_60559_TYPES_EXT)
70 # define HUGE_VAL_F32 (__builtin_huge_valf32 ())
72 #if __HAVE_FLOAT64 && __GLIBC_USE (IEC_60559_TYPES_EXT)
73 # define HUGE_VAL_F64 (__builtin_huge_valf64 ())
75 #if __HAVE_FLOAT128 && __GLIBC_USE (IEC_60559_TYPES_EXT)
76 # define HUGE_VAL_F128 (__builtin_huge_valf128 ())
78 #if __HAVE_FLOAT32X && __GLIBC_USE (IEC_60559_TYPES_EXT)
79 # define HUGE_VAL_F32X (__builtin_huge_valf32x ())
81 #if __HAVE_FLOAT64X && __GLIBC_USE (IEC_60559_TYPES_EXT)
82 # define HUGE_VAL_F64X (__builtin_huge_valf64x ())
84 #if __HAVE_FLOAT128X && __GLIBC_USE (IEC_60559_TYPES_EXT)
85 # define HUGE_VAL_F128X (__builtin_huge_valf128x ())
89 /* IEEE positive infinity. */
90 # if __GNUC_PREREQ (3, 3)
91 # define INFINITY (__builtin_inff ())
93 # define INFINITY HUGE_VALF
96 /* IEEE Not A Number. */
97 # if __GNUC_PREREQ (3, 3)
98 # define NAN (__builtin_nanf (""))
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)
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 (""))
115 #if (__HAVE_FLOAT16 \
116 && __GLIBC_USE (IEC_60559_TYPES_EXT) \
117 && (defined __USE_GNU || !__GLIBC_USE (ISOC2X)))
118 # define SNANF16 (__builtin_nansf16 (""))
120 #if (__HAVE_FLOAT32 \
121 && __GLIBC_USE (IEC_60559_TYPES_EXT) \
122 && (defined __USE_GNU || !__GLIBC_USE (ISOC2X)))
123 # define SNANF32 (__builtin_nansf32 (""))
125 #if (__HAVE_FLOAT64 \
126 && __GLIBC_USE (IEC_60559_TYPES_EXT) \
127 && (defined __USE_GNU || !__GLIBC_USE (ISOC2X)))
128 # define SNANF64 (__builtin_nansf64 (""))
130 #if (__HAVE_FLOAT128 \
131 && __GLIBC_USE (IEC_60559_TYPES_EXT) \
132 && (defined __USE_GNU || !__GLIBC_USE (ISOC2X)))
133 # define SNANF128 (__builtin_nansf128 (""))
135 #if (__HAVE_FLOAT32X \
136 && __GLIBC_USE (IEC_60559_TYPES_EXT) \
137 && (defined __USE_GNU || !__GLIBC_USE (ISOC2X)))
138 # define SNANF32X (__builtin_nansf32x (""))
140 #if (__HAVE_FLOAT64X \
141 && __GLIBC_USE (IEC_60559_TYPES_EXT) \
142 && (defined __USE_GNU || !__GLIBC_USE (ISOC2X)))
143 # define SNANF64X (__builtin_nansf64x (""))
145 #if (__HAVE_FLOAT128X \
146 && __GLIBC_USE (IEC_60559_TYPES_EXT) \
147 && (defined __USE_GNU || !__GLIBC_USE (ISOC2X)))
148 # define SNANF128X (__builtin_nansf128x (""))
151 /* Get __GLIBC_FLT_EVAL_METHOD. */
152 #include <bits/flt-eval-method.h>
155 /* Define the following typedefs.
157 float_t floating-point type at least as wide as `float' used
158 to evaluate `float' expressions
159 double_t floating-point type at least as wide as `double' used
160 to evaluate `double' expressions
162 # if __GLIBC_FLT_EVAL_METHOD == 0 || __GLIBC_FLT_EVAL_METHOD == 16
163 typedef float float_t;
164 typedef double double_t;
165 # elif __GLIBC_FLT_EVAL_METHOD == 1
166 typedef double float_t;
167 typedef double double_t;
168 # elif __GLIBC_FLT_EVAL_METHOD == 2
169 typedef long double float_t;
170 typedef long double double_t;
171 # elif __GLIBC_FLT_EVAL_METHOD == 32
172 typedef _Float32 float_t;
173 typedef double double_t;
174 # elif __GLIBC_FLT_EVAL_METHOD == 33
175 typedef _Float32x float_t;
176 typedef _Float32x double_t;
177 # elif __GLIBC_FLT_EVAL_METHOD == 64
178 typedef _Float64 float_t;
179 typedef _Float64 double_t;
180 # elif __GLIBC_FLT_EVAL_METHOD == 65
181 typedef _Float64x float_t;
182 typedef _Float64x double_t;
183 # elif __GLIBC_FLT_EVAL_METHOD == 128
184 typedef _Float128 float_t;
185 typedef _Float128 double_t;
186 # elif __GLIBC_FLT_EVAL_METHOD == 129
187 typedef _Float128x float_t;
188 typedef _Float128x double_t;
190 # error "Unknown __GLIBC_FLT_EVAL_METHOD"
194 /* Define macros for the return values of ilogb and llogb, based on
195 __FP_LOGB0_IS_MIN and __FP_LOGBNAN_IS_MIN.
197 FP_ILOGB0 Expands to a value returned by `ilogb (0.0)'.
198 FP_ILOGBNAN Expands to a value returned by `ilogb (NAN)'.
199 FP_LLOGB0 Expands to a value returned by `llogb (0.0)'.
200 FP_LLOGBNAN Expands to a value returned by `llogb (NAN)'.
204 #include <bits/fp-logb.h>
206 # if __FP_LOGB0_IS_MIN
207 # define FP_ILOGB0 (-2147483647 - 1)
209 # define FP_ILOGB0 (-2147483647)
211 # if __FP_LOGBNAN_IS_MIN
212 # define FP_ILOGBNAN (-2147483647 - 1)
214 # define FP_ILOGBNAN 2147483647
217 #if __GLIBC_USE (IEC_60559_BFP_EXT_C2X)
218 # if __WORDSIZE == 32
219 # define __FP_LONG_MAX 0x7fffffffL
221 # define __FP_LONG_MAX 0x7fffffffffffffffL
223 # if __FP_LOGB0_IS_MIN
224 # define FP_LLOGB0 (-__FP_LONG_MAX - 1)
226 # define FP_LLOGB0 (-__FP_LONG_MAX)
228 # if __FP_LOGBNAN_IS_MIN
229 # define FP_LLOGBNAN (-__FP_LONG_MAX - 1)
231 # define FP_LLOGBNAN __FP_LONG_MAX
235 /* Get the architecture specific values describing the floating-point
236 evaluation. The following symbols will get defined:
241 If defined it indicates that the `fma' function
242 generally executes about as fast as a multiply and an add.
243 This macro is defined only iff the `fma' function is
244 implemented directly with a hardware multiply-add instructions.
247 #include <bits/fp-fast.h>
249 #if __GLIBC_USE (IEC_60559_BFP_EXT_C2X)
250 /* Rounding direction macros for fromfp functions. */
254 # define FP_INT_UPWARD 0
257 # define FP_INT_DOWNWARD 1
260 # define FP_INT_TOWARDZERO 2
262 FP_INT_TONEARESTFROMZERO =
263 # define FP_INT_TONEARESTFROMZERO 3
264 FP_INT_TONEARESTFROMZERO,
266 # define FP_INT_TONEAREST 4
271 /* The file <bits/mathcalls.h> contains the prototypes for all the
272 actual math functions. These macros are used for those prototypes,
273 so we can easily declare each function as both `name' and `__name',
274 and can declare the float versions `namef' and `__namef'. */
276 #define __SIMD_DECL(function) __CONCAT (__DECL_SIMD_, function)
278 #define __MATHCALL_VEC(function, suffix, args) \
279 __SIMD_DECL (__MATH_PRECNAME (function, suffix)) \
280 __MATHCALL (function, suffix, args)
282 #define __MATHDECL_VEC(type, function,suffix, args) \
283 __SIMD_DECL (__MATH_PRECNAME (function, suffix)) \
284 __MATHDECL(type, function,suffix, args)
286 #define __MATHCALL(function,suffix, args) \
287 __MATHDECL (_Mdouble_,function,suffix, args)
288 #define __MATHDECL(type, function,suffix, args) \
289 __MATHDECL_1(type, function,suffix, args); \
290 __MATHDECL_1(type, __CONCAT(__,function),suffix, args)
291 #define __MATHCALLX(function,suffix, args, attrib) \
292 __MATHDECLX (_Mdouble_,function,suffix, args, attrib)
293 #define __MATHDECLX(type, function,suffix, args, attrib) \
294 __MATHDECL_1(type, function,suffix, args) __attribute__ (attrib); \
295 __MATHDECL_1(type, __CONCAT(__,function),suffix, args) __attribute__ (attrib)
296 #define __MATHDECL_1_IMPL(type, function, suffix, args) \
297 extern type __MATH_PRECNAME(function,suffix) args __THROW
298 #define __MATHDECL_1(type, function, suffix, args) \
299 __MATHDECL_1_IMPL(type, function, suffix, args)
300 /* Ignore the alias by default. The alias is only useful with
302 #define __MATHDECL_ALIAS(type, function, suffix, args, alias) \
303 __MATHDECL_1(type, function, suffix, args)
305 #define __MATHREDIR(type, function, suffix, args, to) \
306 extern type __REDIRECT_NTH (__MATH_PRECNAME (function, suffix), args, to)
308 #define _Mdouble_ double
309 #define __MATH_PRECNAME(name,r) __CONCAT(name,r)
310 #define __MATH_DECLARING_DOUBLE 1
311 #define __MATH_DECLARING_FLOATN 0
312 #include <bits/mathcalls-helper-functions.h>
313 #include <bits/mathcalls.h>
315 #undef __MATH_PRECNAME
316 #undef __MATH_DECLARING_DOUBLE
317 #undef __MATH_DECLARING_FLOATN
322 /* Include the file of declarations again, this time using `float'
323 instead of `double' and appending f to each function name. */
325 # define _Mdouble_ float
326 # define __MATH_PRECNAME(name,r) name##f##r
327 # define __MATH_DECLARING_DOUBLE 0
328 # define __MATH_DECLARING_FLOATN 0
329 # include <bits/mathcalls-helper-functions.h>
330 # include <bits/mathcalls.h>
332 # undef __MATH_PRECNAME
333 # undef __MATH_DECLARING_DOUBLE
334 # undef __MATH_DECLARING_FLOATN
336 # if !(defined __NO_LONG_DOUBLE_MATH && defined _LIBC) \
337 || defined __LDBL_COMPAT \
338 || defined _LIBC_TEST
339 # ifdef __LDBL_COMPAT
342 extern float __nldbl_nexttowardf (float __x, long double __y)
343 __THROW __attribute__ ((__const__));
344 # ifdef __REDIRECT_NTH
345 extern float __REDIRECT_NTH (nexttowardf, (float __x, long double __y),
347 __attribute__ ((__const__));
348 extern double __REDIRECT_NTH (nexttoward, (double __x, long double __y),
349 nextafter) __attribute__ ((__const__));
350 extern long double __REDIRECT_NTH (nexttowardl,
351 (long double __x, long double __y),
352 nextafter) __attribute__ ((__const__));
357 # define __MATHDECL_1(type, function,suffix, args) \
358 __MATHREDIR(type, function, suffix, args, __CONCAT(function,suffix))
360 # elif __LDOUBLE_REDIRECTS_TO_FLOAT128_ABI == 1
361 # ifdef __REDIRECT_NTH
363 extern float __REDIRECT_NTH (nexttowardf, (float __x, long double __y),
364 __nexttowardf_to_ieee128)
365 __attribute__ ((__const__));
366 extern double __REDIRECT_NTH (nexttoward, (double __x, long double __y),
367 __nexttoward_to_ieee128)
368 __attribute__ ((__const__));
370 #define __dremieee128 __remainderieee128
371 #define __gammaieee128 __lgammaieee128
377 # undef __MATHDECL_ALIAS
379 # define __REDIRTO(function, suffix) \
380 __ ## function ## ieee128 ## suffix
381 # define __REDIRTO_ALT(function, suffix) \
382 __ ## function ## f128 ## suffix
384 # define __MATHDECL_1(type, function, suffix, args) \
385 __MATHREDIR (type, function, suffix, args, __REDIRTO (function, suffix))
386 # define __MATHDECL_ALIAS(type, function, suffix, args, alias) \
387 __MATHREDIR (type, function, suffix, args, __REDIRTO_ALT (alias, suffix))
390 /* Include the file of declarations again, this time using `long double'
391 instead of `double' and appending l to each function name. */
393 # define _Mdouble_ long double
394 # define __MATH_PRECNAME(name,r) name##l##r
395 # define __MATH_DECLARING_DOUBLE 0
396 # define __MATH_DECLARING_FLOATN 0
397 # define __MATH_DECLARE_LDOUBLE 1
398 # include <bits/mathcalls-helper-functions.h>
399 # include <bits/mathcalls.h>
402 # undef __MATH_PRECNAME
403 # undef __MATH_DECLARING_DOUBLE
404 # undef __MATH_DECLARING_FLOATN
406 # if defined __LDBL_COMPAT \
407 || __LDOUBLE_REDIRECTS_TO_FLOAT128_ABI == 1
409 # undef __REDIRTO_ALT
411 # undef __MATHDECL_ALIAS
412 # define __MATHDECL_1(type, function, suffix, args) \
413 __MATHDECL_1_IMPL(type, function, suffix, args)
414 # define __MATHDECL_ALIAS(type, function, suffix, args, alias) \
415 __MATHDECL_1(type, function, suffix, args)
417 # endif /* !(__NO_LONG_DOUBLE_MATH && _LIBC) || __LDBL_COMPAT */
419 #endif /* Use ISO C99. */
421 /* Include the file of declarations for _FloatN and _FloatNx
424 #if __HAVE_DISTINCT_FLOAT16 || (__HAVE_FLOAT16 && !defined _LIBC)
425 # define _Mdouble_ _Float16
426 # define __MATH_PRECNAME(name,r) name##f16##r
427 # define __MATH_DECLARING_DOUBLE 0
428 # define __MATH_DECLARING_FLOATN 1
429 # if __HAVE_DISTINCT_FLOAT16
430 # include <bits/mathcalls-helper-functions.h>
432 # if __GLIBC_USE (IEC_60559_TYPES_EXT)
433 # include <bits/mathcalls.h>
436 # undef __MATH_PRECNAME
437 # undef __MATH_DECLARING_DOUBLE
438 # undef __MATH_DECLARING_FLOATN
439 #endif /* __HAVE_DISTINCT_FLOAT16 || (__HAVE_FLOAT16 && !_LIBC). */
441 #if __HAVE_DISTINCT_FLOAT32 || (__HAVE_FLOAT32 && !defined _LIBC)
442 # define _Mdouble_ _Float32
443 # define __MATH_PRECNAME(name,r) name##f32##r
444 # define __MATH_DECLARING_DOUBLE 0
445 # define __MATH_DECLARING_FLOATN 1
446 # if __HAVE_DISTINCT_FLOAT32
447 # include <bits/mathcalls-helper-functions.h>
449 # if __GLIBC_USE (IEC_60559_TYPES_EXT)
450 # include <bits/mathcalls.h>
453 # undef __MATH_PRECNAME
454 # undef __MATH_DECLARING_DOUBLE
455 # undef __MATH_DECLARING_FLOATN
456 #endif /* __HAVE_DISTINCT_FLOAT32 || (__HAVE_FLOAT32 && !_LIBC). */
458 #if __HAVE_DISTINCT_FLOAT64 || (__HAVE_FLOAT64 && !defined _LIBC)
459 # define _Mdouble_ _Float64
460 # define __MATH_PRECNAME(name,r) name##f64##r
461 # define __MATH_DECLARING_DOUBLE 0
462 # define __MATH_DECLARING_FLOATN 1
463 # if __HAVE_DISTINCT_FLOAT64
464 # include <bits/mathcalls-helper-functions.h>
466 # if __GLIBC_USE (IEC_60559_TYPES_EXT)
467 # include <bits/mathcalls.h>
470 # undef __MATH_PRECNAME
471 # undef __MATH_DECLARING_DOUBLE
472 # undef __MATH_DECLARING_FLOATN
473 #endif /* __HAVE_DISTINCT_FLOAT64 || (__HAVE_FLOAT64 && !_LIBC). */
475 #if __HAVE_DISTINCT_FLOAT128 || (__HAVE_FLOAT128 && !defined _LIBC)
476 # define _Mdouble_ _Float128
477 # define __MATH_PRECNAME(name,r) name##f128##r
478 # define __MATH_DECLARING_DOUBLE 0
479 # define __MATH_DECLARING_FLOATN 1
480 # if __HAVE_DISTINCT_FLOAT128
481 # include <bits/mathcalls-helper-functions.h>
483 # if __GLIBC_USE (IEC_60559_TYPES_EXT)
484 # include <bits/mathcalls.h>
487 # undef __MATH_PRECNAME
488 # undef __MATH_DECLARING_DOUBLE
489 # undef __MATH_DECLARING_FLOATN
490 #endif /* __HAVE_DISTINCT_FLOAT128 || (__HAVE_FLOAT128 && !_LIBC). */
492 #if __HAVE_DISTINCT_FLOAT32X || (__HAVE_FLOAT32X && !defined _LIBC)
493 # define _Mdouble_ _Float32x
494 # define __MATH_PRECNAME(name,r) name##f32x##r
495 # define __MATH_DECLARING_DOUBLE 0
496 # define __MATH_DECLARING_FLOATN 1
497 # if __HAVE_DISTINCT_FLOAT32X
498 # include <bits/mathcalls-helper-functions.h>
500 # if __GLIBC_USE (IEC_60559_TYPES_EXT)
501 # include <bits/mathcalls.h>
504 # undef __MATH_PRECNAME
505 # undef __MATH_DECLARING_DOUBLE
506 # undef __MATH_DECLARING_FLOATN
507 #endif /* __HAVE_DISTINCT_FLOAT32X || (__HAVE_FLOAT32X && !_LIBC). */
509 #if __HAVE_DISTINCT_FLOAT64X || (__HAVE_FLOAT64X && !defined _LIBC)
510 # define _Mdouble_ _Float64x
511 # define __MATH_PRECNAME(name,r) name##f64x##r
512 # define __MATH_DECLARING_DOUBLE 0
513 # define __MATH_DECLARING_FLOATN 1
514 # if __HAVE_DISTINCT_FLOAT64X
515 # include <bits/mathcalls-helper-functions.h>
517 # if __GLIBC_USE (IEC_60559_TYPES_EXT)
518 # include <bits/mathcalls.h>
521 # undef __MATH_PRECNAME
522 # undef __MATH_DECLARING_DOUBLE
523 # undef __MATH_DECLARING_FLOATN
524 #endif /* __HAVE_DISTINCT_FLOAT64X || (__HAVE_FLOAT64X && !_LIBC). */
526 #if __HAVE_DISTINCT_FLOAT128X || (__HAVE_FLOAT128X && !defined _LIBC)
527 # define _Mdouble_ _Float128x
528 # define __MATH_PRECNAME(name,r) name##f128x##r
529 # define __MATH_DECLARING_DOUBLE 0
530 # define __MATH_DECLARING_FLOATN 1
531 # if __HAVE_DISTINCT_FLOAT128X
532 # include <bits/mathcalls-helper-functions.h>
534 # if __GLIBC_USE (IEC_60559_TYPES_EXT)
535 # include <bits/mathcalls.h>
538 # undef __MATH_PRECNAME
539 # undef __MATH_DECLARING_DOUBLE
540 # undef __MATH_DECLARING_FLOATN
541 #endif /* __HAVE_DISTINCT_FLOAT128X || (__HAVE_FLOAT128X && !_LIBC). */
543 #undef __MATHDECL_1_IMPL
545 #undef __MATHDECL_ALIAS
549 /* Declare functions returning a narrower type. */
550 #define __MATHCALL_NARROW_ARGS_1 (_Marg_ __x)
551 #define __MATHCALL_NARROW_ARGS_2 (_Marg_ __x, _Marg_ __y)
552 #define __MATHCALL_NARROW_ARGS_3 (_Marg_ __x, _Marg_ __y, _Marg_ __z)
553 #define __MATHCALL_NARROW_NORMAL(func, nargs) \
554 extern _Mret_ func __MATHCALL_NARROW_ARGS_ ## nargs __THROW
555 #define __MATHCALL_NARROW_REDIR(func, redir, nargs) \
556 extern _Mret_ __REDIRECT_NTH (func, __MATHCALL_NARROW_ARGS_ ## nargs, \
558 #define __MATHCALL_NARROW(func, redir, nargs) \
559 __MATHCALL_NARROW_NORMAL (func, nargs)
561 #if __GLIBC_USE (IEC_60559_BFP_EXT_C2X)
563 # define _Mret_ float
564 # define _Marg_ double
565 # define __MATHCALL_NAME(name) f ## name
566 # include <bits/mathcalls-narrow.h>
569 # undef __MATHCALL_NAME
571 # define _Mret_ float
572 # define _Marg_ long double
573 # define __MATHCALL_NAME(name) f ## name ## l
574 # ifdef __LDBL_COMPAT
575 # define __MATHCALL_REDIR_NAME(name) f ## name
576 # undef __MATHCALL_NARROW
577 # define __MATHCALL_NARROW(func, redir, nargs) \
578 __MATHCALL_NARROW_REDIR (func, redir, nargs)
579 # elif __LDOUBLE_REDIRECTS_TO_FLOAT128_ABI == 1
580 # define __MATHCALL_REDIR_NAME(name) __ ## f32 ## name ## ieee128
581 # undef __MATHCALL_NARROW
582 # define __MATHCALL_NARROW(func, redir, nargs) \
583 __MATHCALL_NARROW_REDIR (func, redir, nargs)
585 # include <bits/mathcalls-narrow.h>
588 # undef __MATHCALL_NAME
589 # if defined __LDBL_COMPAT \
590 || __LDOUBLE_REDIRECTS_TO_FLOAT128_ABI == 1
591 # undef __MATHCALL_REDIR_NAME
592 # undef __MATHCALL_NARROW
593 # define __MATHCALL_NARROW(func, redir, nargs) \
594 __MATHCALL_NARROW_NORMAL (func, nargs)
597 # define _Mret_ double
598 # define _Marg_ long double
599 # define __MATHCALL_NAME(name) d ## name ## l
600 # ifdef __LDBL_COMPAT
601 # define __MATHCALL_REDIR_NAME(name) __nldbl_d ## name ## l
602 # undef __MATHCALL_NARROW
603 # define __MATHCALL_NARROW(func, redir, nargs) \
604 __MATHCALL_NARROW_REDIR (func, redir, nargs)
605 # elif __LDOUBLE_REDIRECTS_TO_FLOAT128_ABI == 1
606 # define __MATHCALL_REDIR_NAME(name) __ ## f64 ## name ## ieee128
607 # undef __MATHCALL_NARROW
608 # define __MATHCALL_NARROW(func, redir, nargs) \
609 __MATHCALL_NARROW_REDIR (func, redir, nargs)
611 # include <bits/mathcalls-narrow.h>
614 # undef __MATHCALL_NAME
615 # if defined __LDBL_COMPAT \
616 || __LDOUBLE_REDIRECTS_TO_FLOAT128_ABI == 1
617 # undef __MATHCALL_REDIR_NAME
618 # undef __MATHCALL_NARROW
619 # define __MATHCALL_NARROW(func, redir, nargs) \
620 __MATHCALL_NARROW_NORMAL (func, nargs)
625 #if __GLIBC_USE (IEC_60559_TYPES_EXT)
627 # if __HAVE_FLOAT16 && __HAVE_FLOAT32
628 # define _Mret_ _Float16
629 # define _Marg_ _Float32
630 # define __MATHCALL_NAME(name) f16 ## name ## f32
631 # include <bits/mathcalls-narrow.h>
634 # undef __MATHCALL_NAME
637 # if __HAVE_FLOAT16 && __HAVE_FLOAT32X
638 # define _Mret_ _Float16
639 # define _Marg_ _Float32x
640 # define __MATHCALL_NAME(name) f16 ## name ## f32x
641 # include <bits/mathcalls-narrow.h>
644 # undef __MATHCALL_NAME
647 # if __HAVE_FLOAT16 && __HAVE_FLOAT64
648 # define _Mret_ _Float16
649 # define _Marg_ _Float64
650 # define __MATHCALL_NAME(name) f16 ## name ## f64
651 # include <bits/mathcalls-narrow.h>
654 # undef __MATHCALL_NAME
657 # if __HAVE_FLOAT16 && __HAVE_FLOAT64X
658 # define _Mret_ _Float16
659 # define _Marg_ _Float64x
660 # define __MATHCALL_NAME(name) f16 ## name ## f64x
661 # include <bits/mathcalls-narrow.h>
664 # undef __MATHCALL_NAME
667 # if __HAVE_FLOAT16 && __HAVE_FLOAT128
668 # define _Mret_ _Float16
669 # define _Marg_ _Float128
670 # define __MATHCALL_NAME(name) f16 ## name ## f128
671 # include <bits/mathcalls-narrow.h>
674 # undef __MATHCALL_NAME
677 # if __HAVE_FLOAT16 && __HAVE_FLOAT128X
678 # define _Mret_ _Float16
679 # define _Marg_ _Float128x
680 # define __MATHCALL_NAME(name) f16 ## name ## f128x
681 # include <bits/mathcalls-narrow.h>
684 # undef __MATHCALL_NAME
687 # if __HAVE_FLOAT32 && __HAVE_FLOAT32X
688 # define _Mret_ _Float32
689 # define _Marg_ _Float32x
690 # define __MATHCALL_NAME(name) f32 ## name ## f32x
691 # include <bits/mathcalls-narrow.h>
694 # undef __MATHCALL_NAME
697 # if __HAVE_FLOAT32 && __HAVE_FLOAT64
698 # define _Mret_ _Float32
699 # define _Marg_ _Float64
700 # define __MATHCALL_NAME(name) f32 ## name ## f64
701 # include <bits/mathcalls-narrow.h>
704 # undef __MATHCALL_NAME
707 # if __HAVE_FLOAT32 && __HAVE_FLOAT64X
708 # define _Mret_ _Float32
709 # define _Marg_ _Float64x
710 # define __MATHCALL_NAME(name) f32 ## name ## f64x
711 # include <bits/mathcalls-narrow.h>
714 # undef __MATHCALL_NAME
717 # if __HAVE_FLOAT32 && __HAVE_FLOAT128
718 # define _Mret_ _Float32
719 # define _Marg_ _Float128
720 # define __MATHCALL_NAME(name) f32 ## name ## f128
721 # include <bits/mathcalls-narrow.h>
724 # undef __MATHCALL_NAME
727 # if __HAVE_FLOAT32 && __HAVE_FLOAT128X
728 # define _Mret_ _Float32
729 # define _Marg_ _Float128x
730 # define __MATHCALL_NAME(name) f32 ## name ## f128x
731 # include <bits/mathcalls-narrow.h>
734 # undef __MATHCALL_NAME
737 # if __HAVE_FLOAT32X && __HAVE_FLOAT64
738 # define _Mret_ _Float32x
739 # define _Marg_ _Float64
740 # define __MATHCALL_NAME(name) f32x ## name ## f64
741 # include <bits/mathcalls-narrow.h>
744 # undef __MATHCALL_NAME
747 # if __HAVE_FLOAT32X && __HAVE_FLOAT64X
748 # define _Mret_ _Float32x
749 # define _Marg_ _Float64x
750 # define __MATHCALL_NAME(name) f32x ## name ## f64x
751 # include <bits/mathcalls-narrow.h>
754 # undef __MATHCALL_NAME
757 # if __HAVE_FLOAT32X && __HAVE_FLOAT128
758 # define _Mret_ _Float32x
759 # define _Marg_ _Float128
760 # define __MATHCALL_NAME(name) f32x ## name ## f128
761 # include <bits/mathcalls-narrow.h>
764 # undef __MATHCALL_NAME
767 # if __HAVE_FLOAT32X && __HAVE_FLOAT128X
768 # define _Mret_ _Float32x
769 # define _Marg_ _Float128x
770 # define __MATHCALL_NAME(name) f32x ## name ## f128x
771 # include <bits/mathcalls-narrow.h>
774 # undef __MATHCALL_NAME
777 # if __HAVE_FLOAT64 && __HAVE_FLOAT64X
778 # define _Mret_ _Float64
779 # define _Marg_ _Float64x
780 # define __MATHCALL_NAME(name) f64 ## name ## f64x
781 # include <bits/mathcalls-narrow.h>
784 # undef __MATHCALL_NAME
787 # if __HAVE_FLOAT64 && __HAVE_FLOAT128
788 # define _Mret_ _Float64
789 # define _Marg_ _Float128
790 # define __MATHCALL_NAME(name) f64 ## name ## f128
791 # include <bits/mathcalls-narrow.h>
794 # undef __MATHCALL_NAME
797 # if __HAVE_FLOAT64 && __HAVE_FLOAT128X
798 # define _Mret_ _Float64
799 # define _Marg_ _Float128x
800 # define __MATHCALL_NAME(name) f64 ## name ## f128x
801 # include <bits/mathcalls-narrow.h>
804 # undef __MATHCALL_NAME
807 # if __HAVE_FLOAT64X && __HAVE_FLOAT128
808 # define _Mret_ _Float64x
809 # define _Marg_ _Float128
810 # define __MATHCALL_NAME(name) f64x ## name ## f128
811 # include <bits/mathcalls-narrow.h>
814 # undef __MATHCALL_NAME
817 # if __HAVE_FLOAT64X && __HAVE_FLOAT128X
818 # define _Mret_ _Float64x
819 # define _Marg_ _Float128x
820 # define __MATHCALL_NAME(name) f64x ## name ## f128x
821 # include <bits/mathcalls-narrow.h>
824 # undef __MATHCALL_NAME
827 # if __HAVE_FLOAT128 && __HAVE_FLOAT128X
828 # define _Mret_ _Float128
829 # define _Marg_ _Float128x
830 # define __MATHCALL_NAME(name) f128 ## name ## f128x
831 # include <bits/mathcalls-narrow.h>
834 # undef __MATHCALL_NAME
839 #undef __MATHCALL_NARROW_ARGS_1
840 #undef __MATHCALL_NARROW_ARGS_2
841 #undef __MATHCALL_NARROW_ARGS_3
842 #undef __MATHCALL_NARROW_NORMAL
843 #undef __MATHCALL_NARROW_REDIR
844 #undef __MATHCALL_NARROW
846 #if defined __USE_MISC || defined __USE_XOPEN
847 /* This variable is used by `gamma' and `lgamma'. */
851 #if (__HAVE_DISTINCT_FLOAT16 \
852 || __HAVE_DISTINCT_FLOAT32 \
853 || __HAVE_DISTINCT_FLOAT64 \
854 || __HAVE_DISTINCT_FLOAT32X \
855 || __HAVE_DISTINCT_FLOAT64X \
856 || __HAVE_DISTINCT_FLOAT128X)
857 # error "Unsupported _FloatN or _FloatNx types for <math.h>."
860 /* Depending on the type of TG_ARG, call an appropriately suffixed
861 version of FUNC with arguments (including parentheses) ARGS.
862 Suffixed functions may not exist for long double if it has the same
863 format as double, or for other types with the same format as float,
864 double or long double. The behavior is undefined if the argument
865 does not have a real floating type. The definition may use a
866 conditional expression, so all suffixed versions of FUNC must
867 return the same type (FUNC may include a cast if necessary rather
868 than being a single identifier). */
869 #ifdef __NO_LONG_DOUBLE_MATH
870 # if __HAVE_DISTINCT_FLOAT128
871 # error "Distinct _Float128 without distinct long double not supported."
873 # define __MATH_TG(TG_ARG, FUNC, ARGS) \
874 (sizeof (TG_ARG) == sizeof (float) ? FUNC ## f ARGS : FUNC ARGS)
875 #elif __HAVE_DISTINCT_FLOAT128
876 # if __HAVE_GENERIC_SELECTION
877 # if __HAVE_FLOATN_NOT_TYPEDEF && __HAVE_FLOAT32
878 # define __MATH_TG_F32(FUNC, ARGS) _Float32: FUNC ## f ARGS,
880 # define __MATH_TG_F32(FUNC, ARGS)
882 # if __HAVE_FLOATN_NOT_TYPEDEF && __HAVE_FLOAT64X
883 # if __HAVE_FLOAT64X_LONG_DOUBLE
884 # define __MATH_TG_F64X(FUNC, ARGS) _Float64x: FUNC ## l ARGS,
886 # define __MATH_TG_F64X(FUNC, ARGS) _Float64x: FUNC ## f128 ARGS,
889 # define __MATH_TG_F64X(FUNC, ARGS)
891 # define __MATH_TG(TG_ARG, FUNC, ARGS) \
892 _Generic ((TG_ARG), \
893 float: FUNC ## f ARGS, \
894 __MATH_TG_F32 (FUNC, ARGS) \
895 default: FUNC ARGS, \
896 long double: FUNC ## l ARGS, \
897 __MATH_TG_F64X (FUNC, ARGS) \
898 _Float128: FUNC ## f128 ARGS)
900 # if __HAVE_FLOATN_NOT_TYPEDEF
901 # error "Non-typedef _FloatN but no _Generic."
903 # define __MATH_TG(TG_ARG, FUNC, ARGS) \
904 __builtin_choose_expr \
905 (__builtin_types_compatible_p (__typeof (TG_ARG), float), \
907 __builtin_choose_expr \
908 (__builtin_types_compatible_p (__typeof (TG_ARG), double), \
910 __builtin_choose_expr \
911 (__builtin_types_compatible_p (__typeof (TG_ARG), long double), \
916 # define __MATH_TG(TG_ARG, FUNC, ARGS) \
917 (sizeof (TG_ARG) == sizeof (float) \
919 : sizeof (TG_ARG) == sizeof (double) \
924 /* ISO C99 defines some generic macros which work on any data type. */
927 /* All floating-point numbers can be put in one of these categories. */
934 # define FP_INFINITE 1
940 # define FP_SUBNORMAL 3
947 /* GCC bug 66462 means we cannot use the math builtins with -fsignaling-nan,
948 so disable builtins if this is enabled. When fixed in a newer GCC,
949 the __SUPPORT_SNAN__ check may be skipped for those versions. */
951 /* Return number of classification appropriate for X. */
952 # if ((__GNUC_PREREQ (4,4) && !defined __SUPPORT_SNAN__) \
953 || __glibc_clang_prereq (2,8)) \
954 && (!defined __OPTIMIZE_SIZE__ || defined __cplusplus)
955 /* The check for __cplusplus allows the use of the builtin, even
956 when optimization for size is on. This is provided for
957 libstdc++, only to let its configure test work when it is built
958 with -Os. No further use of this definition of fpclassify is
959 expected in C++ mode, since libstdc++ provides its own version
960 of fpclassify in cmath (which undefines fpclassify). */
961 # define fpclassify(x) __builtin_fpclassify (FP_NAN, FP_INFINITE, \
962 FP_NORMAL, FP_SUBNORMAL, FP_ZERO, x)
964 # define fpclassify(x) __MATH_TG ((x), __fpclassify, (x))
967 /* Return nonzero value if sign of X is negative. */
968 # if __GNUC_PREREQ (6,0) || __glibc_clang_prereq (3,3)
969 # define signbit(x) __builtin_signbit (x)
970 # elif defined __cplusplus
971 /* In C++ mode, __MATH_TG cannot be used, because it relies on
972 __builtin_types_compatible_p, which is a C-only builtin.
973 The check for __cplusplus allows the use of the builtin instead of
974 __MATH_TG. This is provided for libstdc++, only to let its configure
975 test work. No further use of this definition of signbit is expected
976 in C++ mode, since libstdc++ provides its own version of signbit
977 in cmath (which undefines signbit). */
978 # define signbit(x) __builtin_signbitl (x)
979 # elif __GNUC_PREREQ (4,0)
980 # define signbit(x) __MATH_TG ((x), __builtin_signbit, (x))
982 # define signbit(x) __MATH_TG ((x), __signbit, (x))
985 /* Return nonzero value if X is not +-Inf or NaN. */
986 # if (__GNUC_PREREQ (4,4) && !defined __SUPPORT_SNAN__) \
987 || __glibc_clang_prereq (2,8)
988 # define isfinite(x) __builtin_isfinite (x)
990 # define isfinite(x) __MATH_TG ((x), __finite, (x))
993 /* Return nonzero value if X is neither zero, subnormal, Inf, nor NaN. */
994 # if (__GNUC_PREREQ (4,4) && !defined __SUPPORT_SNAN__) \
995 || __glibc_clang_prereq (2,8)
996 # define isnormal(x) __builtin_isnormal (x)
998 # define isnormal(x) (fpclassify (x) == FP_NORMAL)
1001 /* Return nonzero value if X is a NaN. We could use `fpclassify' but
1002 we already have this functions `__isnan' and it is faster. */
1003 # if (__GNUC_PREREQ (4,4) && !defined __SUPPORT_SNAN__) \
1004 || __glibc_clang_prereq (2,8)
1005 # define isnan(x) __builtin_isnan (x)
1007 # define isnan(x) __MATH_TG ((x), __isnan, (x))
1010 /* Return nonzero value if X is positive or negative infinity. */
1011 # if __HAVE_DISTINCT_FLOAT128 && !__GNUC_PREREQ (7,0) \
1012 && !defined __SUPPORT_SNAN__ && !defined __cplusplus
1013 /* Since __builtin_isinf_sign is broken for float128 before GCC 7.0,
1014 use the helper function, __isinff128, with older compilers. This is
1015 only provided for C mode, because in C++ mode, GCC has no support
1016 for __builtin_types_compatible_p (and when in C++ mode, this macro is
1017 not used anyway, because libstdc++ headers undefine it). */
1019 (__builtin_types_compatible_p (__typeof (x), _Float128) \
1020 ? __isinff128 (x) : __builtin_isinf_sign (x))
1021 # elif (__GNUC_PREREQ (4,4) && !defined __SUPPORT_SNAN__) \
1022 || __glibc_clang_prereq (3,7)
1023 # define isinf(x) __builtin_isinf_sign (x)
1025 # define isinf(x) __MATH_TG ((x), __isinf, (x))
1028 /* Bitmasks for the math_errhandling macro. */
1029 # define MATH_ERRNO 1 /* errno set by math functions. */
1030 # define MATH_ERREXCEPT 2 /* Exceptions raised by math functions. */
1032 /* By default all math functions support both errno and exception handling
1033 (except for soft floating point implementations which may only support
1034 errno handling). If errno handling is disabled, exceptions are still
1035 supported by GLIBC. Set math_errhandling to 0 with -ffast-math (this is
1036 nonconforming but it is more useful than leaving it undefined). */
1037 # ifdef __FAST_MATH__
1038 # define math_errhandling 0
1039 # elif defined __NO_MATH_ERRNO__
1040 # define math_errhandling (MATH_ERREXCEPT)
1042 # define math_errhandling (MATH_ERRNO | MATH_ERREXCEPT)
1045 #endif /* Use ISO C99. */
1047 #if __GLIBC_USE (IEC_60559_BFP_EXT_C2X)
1048 # include <bits/iscanonical.h>
1050 /* Return nonzero value if X is a signaling NaN. */
1051 # ifndef __cplusplus
1052 # define issignaling(x) __MATH_TG ((x), __issignaling, (x))
1054 /* In C++ mode, __MATH_TG cannot be used, because it relies on
1055 __builtin_types_compatible_p, which is a C-only builtin. On the
1056 other hand, overloading provides the means to distinguish between
1057 the floating-point types. The overloading resolution will match
1058 the correct parameter (regardless of type qualifiers (i.e.: const
1061 inline int issignaling (float __val) { return __issignalingf (__val); }
1062 inline int issignaling (double __val) { return __issignaling (__val); }
1064 issignaling (long double __val)
1066 # ifdef __NO_LONG_DOUBLE_MATH
1067 return __issignaling (__val);
1069 return __issignalingl (__val);
1072 # if __HAVE_FLOAT128_UNLIKE_LDBL
1073 /* When using an IEEE 128-bit long double, _Float128 is defined as long double
1075 inline int issignaling (_Float128 __val) { return __issignalingf128 (__val); }
1080 /* Return nonzero value if X is subnormal. */
1081 # define issubnormal(x) (fpclassify (x) == FP_SUBNORMAL)
1083 /* Return nonzero value if X is zero. */
1084 # ifndef __cplusplus
1085 # ifdef __SUPPORT_SNAN__
1086 # define iszero(x) (fpclassify (x) == FP_ZERO)
1088 # define iszero(x) (((__typeof (x)) (x)) == 0)
1090 # else /* __cplusplus */
1092 # ifdef __SUPPORT_SNAN__
1094 iszero (float __val)
1096 return __fpclassifyf (__val) == FP_ZERO;
1099 iszero (double __val)
1101 return __fpclassify (__val) == FP_ZERO;
1104 iszero (long double __val)
1106 # ifdef __NO_LONG_DOUBLE_MATH
1107 return __fpclassify (__val) == FP_ZERO;
1109 return __fpclassifyl (__val) == FP_ZERO;
1112 # if __HAVE_FLOAT128_UNLIKE_LDBL
1113 /* When using an IEEE 128-bit long double, _Float128 is defined as long double
1116 iszero (_Float128 __val)
1118 return __fpclassifyf128 (__val) == FP_ZERO;
1122 template <class __T> inline bool
1129 # endif /* __cplusplus */
1130 #endif /* Use IEC_60559_BFP_EXT. */
1133 /* X/Open wants another strange constant. */
1134 # define MAXFLOAT 3.40282347e+38F
1138 /* Some useful constants. */
1139 #if defined __USE_MISC || defined __USE_XOPEN
1140 # define M_E 2.7182818284590452354 /* e */
1141 # define M_LOG2E 1.4426950408889634074 /* log_2 e */
1142 # define M_LOG10E 0.43429448190325182765 /* log_10 e */
1143 # define M_LN2 0.69314718055994530942 /* log_e 2 */
1144 # define M_LN10 2.30258509299404568402 /* log_e 10 */
1145 # define M_PI 3.14159265358979323846 /* pi */
1146 # define M_PI_2 1.57079632679489661923 /* pi/2 */
1147 # define M_PI_4 0.78539816339744830962 /* pi/4 */
1148 # define M_1_PI 0.31830988618379067154 /* 1/pi */
1149 # define M_2_PI 0.63661977236758134308 /* 2/pi */
1150 # define M_2_SQRTPI 1.12837916709551257390 /* 2/sqrt(pi) */
1151 # define M_SQRT2 1.41421356237309504880 /* sqrt(2) */
1152 # define M_SQRT1_2 0.70710678118654752440 /* 1/sqrt(2) */
1155 /* The above constants are not adequate for computation using `long double's.
1156 Therefore we provide as an extension constants with similar names as a
1157 GNU extension. Provide enough digits for the 128-bit IEEE quad. */
1159 # define M_El 2.718281828459045235360287471352662498L /* e */
1160 # define M_LOG2El 1.442695040888963407359924681001892137L /* log_2 e */
1161 # define M_LOG10El 0.434294481903251827651128918916605082L /* log_10 e */
1162 # define M_LN2l 0.693147180559945309417232121458176568L /* log_e 2 */
1163 # define M_LN10l 2.302585092994045684017991454684364208L /* log_e 10 */
1164 # define M_PIl 3.141592653589793238462643383279502884L /* pi */
1165 # define M_PI_2l 1.570796326794896619231321691639751442L /* pi/2 */
1166 # define M_PI_4l 0.785398163397448309615660845819875721L /* pi/4 */
1167 # define M_1_PIl 0.318309886183790671537767526745028724L /* 1/pi */
1168 # define M_2_PIl 0.636619772367581343075535053490057448L /* 2/pi */
1169 # define M_2_SQRTPIl 1.128379167095512573896158903121545172L /* 2/sqrt(pi) */
1170 # define M_SQRT2l 1.414213562373095048801688724209698079L /* sqrt(2) */
1171 # define M_SQRT1_2l 0.707106781186547524400844362104849039L /* 1/sqrt(2) */
1174 #if __HAVE_FLOAT16 && defined __USE_GNU
1175 # define M_Ef16 __f16 (2.718281828459045235360287471352662498) /* e */
1176 # define M_LOG2Ef16 __f16 (1.442695040888963407359924681001892137) /* log_2 e */
1177 # define M_LOG10Ef16 __f16 (0.434294481903251827651128918916605082) /* log_10 e */
1178 # define M_LN2f16 __f16 (0.693147180559945309417232121458176568) /* log_e 2 */
1179 # define M_LN10f16 __f16 (2.302585092994045684017991454684364208) /* log_e 10 */
1180 # define M_PIf16 __f16 (3.141592653589793238462643383279502884) /* pi */
1181 # define M_PI_2f16 __f16 (1.570796326794896619231321691639751442) /* pi/2 */
1182 # define M_PI_4f16 __f16 (0.785398163397448309615660845819875721) /* pi/4 */
1183 # define M_1_PIf16 __f16 (0.318309886183790671537767526745028724) /* 1/pi */
1184 # define M_2_PIf16 __f16 (0.636619772367581343075535053490057448) /* 2/pi */
1185 # define M_2_SQRTPIf16 __f16 (1.128379167095512573896158903121545172) /* 2/sqrt(pi) */
1186 # define M_SQRT2f16 __f16 (1.414213562373095048801688724209698079) /* sqrt(2) */
1187 # define M_SQRT1_2f16 __f16 (0.707106781186547524400844362104849039) /* 1/sqrt(2) */
1190 #if __HAVE_FLOAT32 && defined __USE_GNU
1191 # define M_Ef32 __f32 (2.718281828459045235360287471352662498) /* e */
1192 # define M_LOG2Ef32 __f32 (1.442695040888963407359924681001892137) /* log_2 e */
1193 # define M_LOG10Ef32 __f32 (0.434294481903251827651128918916605082) /* log_10 e */
1194 # define M_LN2f32 __f32 (0.693147180559945309417232121458176568) /* log_e 2 */
1195 # define M_LN10f32 __f32 (2.302585092994045684017991454684364208) /* log_e 10 */
1196 # define M_PIf32 __f32 (3.141592653589793238462643383279502884) /* pi */
1197 # define M_PI_2f32 __f32 (1.570796326794896619231321691639751442) /* pi/2 */
1198 # define M_PI_4f32 __f32 (0.785398163397448309615660845819875721) /* pi/4 */
1199 # define M_1_PIf32 __f32 (0.318309886183790671537767526745028724) /* 1/pi */
1200 # define M_2_PIf32 __f32 (0.636619772367581343075535053490057448) /* 2/pi */
1201 # define M_2_SQRTPIf32 __f32 (1.128379167095512573896158903121545172) /* 2/sqrt(pi) */
1202 # define M_SQRT2f32 __f32 (1.414213562373095048801688724209698079) /* sqrt(2) */
1203 # define M_SQRT1_2f32 __f32 (0.707106781186547524400844362104849039) /* 1/sqrt(2) */
1206 #if __HAVE_FLOAT64 && defined __USE_GNU
1207 # define M_Ef64 __f64 (2.718281828459045235360287471352662498) /* e */
1208 # define M_LOG2Ef64 __f64 (1.442695040888963407359924681001892137) /* log_2 e */
1209 # define M_LOG10Ef64 __f64 (0.434294481903251827651128918916605082) /* log_10 e */
1210 # define M_LN2f64 __f64 (0.693147180559945309417232121458176568) /* log_e 2 */
1211 # define M_LN10f64 __f64 (2.302585092994045684017991454684364208) /* log_e 10 */
1212 # define M_PIf64 __f64 (3.141592653589793238462643383279502884) /* pi */
1213 # define M_PI_2f64 __f64 (1.570796326794896619231321691639751442) /* pi/2 */
1214 # define M_PI_4f64 __f64 (0.785398163397448309615660845819875721) /* pi/4 */
1215 # define M_1_PIf64 __f64 (0.318309886183790671537767526745028724) /* 1/pi */
1216 # define M_2_PIf64 __f64 (0.636619772367581343075535053490057448) /* 2/pi */
1217 # define M_2_SQRTPIf64 __f64 (1.128379167095512573896158903121545172) /* 2/sqrt(pi) */
1218 # define M_SQRT2f64 __f64 (1.414213562373095048801688724209698079) /* sqrt(2) */
1219 # define M_SQRT1_2f64 __f64 (0.707106781186547524400844362104849039) /* 1/sqrt(2) */
1222 #if __HAVE_FLOAT128 && defined __USE_GNU
1223 # define M_Ef128 __f128 (2.718281828459045235360287471352662498) /* e */
1224 # define M_LOG2Ef128 __f128 (1.442695040888963407359924681001892137) /* log_2 e */
1225 # define M_LOG10Ef128 __f128 (0.434294481903251827651128918916605082) /* log_10 e */
1226 # define M_LN2f128 __f128 (0.693147180559945309417232121458176568) /* log_e 2 */
1227 # define M_LN10f128 __f128 (2.302585092994045684017991454684364208) /* log_e 10 */
1228 # define M_PIf128 __f128 (3.141592653589793238462643383279502884) /* pi */
1229 # define M_PI_2f128 __f128 (1.570796326794896619231321691639751442) /* pi/2 */
1230 # define M_PI_4f128 __f128 (0.785398163397448309615660845819875721) /* pi/4 */
1231 # define M_1_PIf128 __f128 (0.318309886183790671537767526745028724) /* 1/pi */
1232 # define M_2_PIf128 __f128 (0.636619772367581343075535053490057448) /* 2/pi */
1233 # define M_2_SQRTPIf128 __f128 (1.128379167095512573896158903121545172) /* 2/sqrt(pi) */
1234 # define M_SQRT2f128 __f128 (1.414213562373095048801688724209698079) /* sqrt(2) */
1235 # define M_SQRT1_2f128 __f128 (0.707106781186547524400844362104849039) /* 1/sqrt(2) */
1238 #if __HAVE_FLOAT32X && defined __USE_GNU
1239 # define M_Ef32x __f32x (2.718281828459045235360287471352662498) /* e */
1240 # define M_LOG2Ef32x __f32x (1.442695040888963407359924681001892137) /* log_2 e */
1241 # define M_LOG10Ef32x __f32x (0.434294481903251827651128918916605082) /* log_10 e */
1242 # define M_LN2f32x __f32x (0.693147180559945309417232121458176568) /* log_e 2 */
1243 # define M_LN10f32x __f32x (2.302585092994045684017991454684364208) /* log_e 10 */
1244 # define M_PIf32x __f32x (3.141592653589793238462643383279502884) /* pi */
1245 # define M_PI_2f32x __f32x (1.570796326794896619231321691639751442) /* pi/2 */
1246 # define M_PI_4f32x __f32x (0.785398163397448309615660845819875721) /* pi/4 */
1247 # define M_1_PIf32x __f32x (0.318309886183790671537767526745028724) /* 1/pi */
1248 # define M_2_PIf32x __f32x (0.636619772367581343075535053490057448) /* 2/pi */
1249 # define M_2_SQRTPIf32x __f32x (1.128379167095512573896158903121545172) /* 2/sqrt(pi) */
1250 # define M_SQRT2f32x __f32x (1.414213562373095048801688724209698079) /* sqrt(2) */
1251 # define M_SQRT1_2f32x __f32x (0.707106781186547524400844362104849039) /* 1/sqrt(2) */
1254 #if __HAVE_FLOAT64X && defined __USE_GNU
1255 # define M_Ef64x __f64x (2.718281828459045235360287471352662498) /* e */
1256 # define M_LOG2Ef64x __f64x (1.442695040888963407359924681001892137) /* log_2 e */
1257 # define M_LOG10Ef64x __f64x (0.434294481903251827651128918916605082) /* log_10 e */
1258 # define M_LN2f64x __f64x (0.693147180559945309417232121458176568) /* log_e 2 */
1259 # define M_LN10f64x __f64x (2.302585092994045684017991454684364208) /* log_e 10 */
1260 # define M_PIf64x __f64x (3.141592653589793238462643383279502884) /* pi */
1261 # define M_PI_2f64x __f64x (1.570796326794896619231321691639751442) /* pi/2 */
1262 # define M_PI_4f64x __f64x (0.785398163397448309615660845819875721) /* pi/4 */
1263 # define M_1_PIf64x __f64x (0.318309886183790671537767526745028724) /* 1/pi */
1264 # define M_2_PIf64x __f64x (0.636619772367581343075535053490057448) /* 2/pi */
1265 # define M_2_SQRTPIf64x __f64x (1.128379167095512573896158903121545172) /* 2/sqrt(pi) */
1266 # define M_SQRT2f64x __f64x (1.414213562373095048801688724209698079) /* sqrt(2) */
1267 # define M_SQRT1_2f64x __f64x (0.707106781186547524400844362104849039) /* 1/sqrt(2) */
1270 #if __HAVE_FLOAT128X && defined __USE_GNU
1271 # error "M_* values needed for _Float128x"
1275 # if __GNUC_PREREQ (3, 1)
1276 /* ISO C99 defines some macros to compare number while taking care for
1277 unordered numbers. Many FPUs provide special instructions to support
1278 these operations. Generic support in GCC for these as builtins went
1279 in 2.97, but not all cpus added their patterns until 3.1. Therefore
1280 we enable the builtins from 3.1 onwards and use a generic implementation
1282 # define isgreater(x, y) __builtin_isgreater(x, y)
1283 # define isgreaterequal(x, y) __builtin_isgreaterequal(x, y)
1284 # define isless(x, y) __builtin_isless(x, y)
1285 # define islessequal(x, y) __builtin_islessequal(x, y)
1286 # define islessgreater(x, y) __builtin_islessgreater(x, y)
1287 # define isunordered(x, y) __builtin_isunordered(x, y)
1289 # define isgreater(x, y) \
1290 (__extension__ ({ __typeof__ (x) __x = (x); __typeof__ (y) __y = (y); \
1291 !isunordered (__x, __y) && __x > __y; }))
1292 # define isgreaterequal(x, y) \
1293 (__extension__ ({ __typeof__ (x) __x = (x); __typeof__ (y) __y = (y); \
1294 !isunordered (__x, __y) && __x >= __y; }))
1295 # define isless(x, y) \
1296 (__extension__ ({ __typeof__ (x) __x = (x); __typeof__ (y) __y = (y); \
1297 !isunordered (__x, __y) && __x < __y; }))
1298 # define islessequal(x, y) \
1299 (__extension__ ({ __typeof__ (x) __x = (x); __typeof__ (y) __y = (y); \
1300 !isunordered (__x, __y) && __x <= __y; }))
1301 # define islessgreater(x, y) \
1302 (__extension__ ({ __typeof__ (x) __x = (x); __typeof__ (y) __y = (y); \
1303 !isunordered (__x, __y) && __x != __y; }))
1304 /* isunordered must always check both operands first for signaling NaNs. */
1305 # define isunordered(x, y) \
1306 (__extension__ ({ __typeof__ (x) __u = (x); __typeof__ (y) __v = (y); \
1307 __u != __v && (__u != __u || __v != __v); }))
1311 #if __GLIBC_USE (IEC_60559_BFP_EXT_C2X)
1312 /* An expression whose type has the widest of the evaluation formats
1313 of X and Y (which are of floating-point types). */
1314 # if __FLT_EVAL_METHOD__ == 2 || __FLT_EVAL_METHOD__ > 64
1315 # define __MATH_EVAL_FMT2(x, y) ((x) + (y) + 0.0L)
1316 # elif __FLT_EVAL_METHOD__ == 1 || __FLT_EVAL_METHOD__ > 32
1317 # define __MATH_EVAL_FMT2(x, y) ((x) + (y) + 0.0)
1318 # elif __FLT_EVAL_METHOD__ == 0 || __FLT_EVAL_METHOD__ == 32
1319 # define __MATH_EVAL_FMT2(x, y) ((x) + (y) + 0.0f)
1321 # define __MATH_EVAL_FMT2(x, y) ((x) + (y))
1324 /* Return X == Y but raising "invalid" and setting errno if X or Y is
1326 # if !defined __cplusplus || (__cplusplus < 201103L && !defined __GNUC__)
1327 # define iseqsig(x, y) \
1328 __MATH_TG (__MATH_EVAL_FMT2 (x, y), __iseqsig, ((x), (y)))
1330 /* In C++ mode, __MATH_TG cannot be used, because it relies on
1331 __builtin_types_compatible_p, which is a C-only builtin. Moreover,
1332 the comparison macros from ISO C take two floating-point arguments,
1333 which need not have the same type. Choosing what underlying function
1334 to call requires evaluating the formats of the arguments, then
1335 selecting which is wider. The macro __MATH_EVAL_FMT2 provides this
1336 information, however, only the type of the macro expansion is
1337 relevant (actually evaluating the expression would be incorrect).
1338 Thus, the type is used as a template parameter for __iseqsig_type,
1339 which calls the appropriate underlying function. */
1341 template<typename> struct __iseqsig_type;
1343 template<> struct __iseqsig_type<float>
1345 static int __call (float __x, float __y) throw ()
1347 return __iseqsigf (__x, __y);
1351 template<> struct __iseqsig_type<double>
1353 static int __call (double __x, double __y) throw ()
1355 return __iseqsig (__x, __y);
1359 template<> struct __iseqsig_type<long double>
1361 static int __call (long double __x, long double __y) throw ()
1363 # ifndef __NO_LONG_DOUBLE_MATH
1364 return __iseqsigl (__x, __y);
1366 return __iseqsig (__x, __y);
1371 # if __HAVE_FLOAT128_UNLIKE_LDBL
1372 /* When using an IEEE 128-bit long double, _Float128 is defined as long double
1374 template<> struct __iseqsig_type<_Float128>
1376 static int __call (_Float128 __x, _Float128 __y) throw ()
1378 return __iseqsigf128 (__x, __y);
1383 template<typename _T1, typename _T2>
1385 iseqsig (_T1 __x, _T2 __y) throw ()
1387 # if __cplusplus >= 201103L
1388 typedef decltype (__MATH_EVAL_FMT2 (__x, __y)) _T3;
1390 typedef __typeof (__MATH_EVAL_FMT2 (__x, __y)) _T3;
1392 return __iseqsig_type<_T3>::__call (__x, __y);
1395 } /* extern "C++" */
1396 # endif /* __cplusplus */