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>
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 && __GLIBC_USE (IEC_60559_TYPES_EXT)
116 # define SNANF16 (__builtin_nansf16 (""))
118 #if __HAVE_FLOAT32 && __GLIBC_USE (IEC_60559_TYPES_EXT)
119 # define SNANF32 (__builtin_nansf32 (""))
121 #if __HAVE_FLOAT64 && __GLIBC_USE (IEC_60559_TYPES_EXT)
122 # define SNANF64 (__builtin_nansf64 (""))
124 #if __HAVE_FLOAT128 && __GLIBC_USE (IEC_60559_TYPES_EXT)
125 # define SNANF128 (__builtin_nansf128 (""))
127 #if __HAVE_FLOAT32X && __GLIBC_USE (IEC_60559_TYPES_EXT)
128 # define SNANF32X (__builtin_nansf32x (""))
130 #if __HAVE_FLOAT64X && __GLIBC_USE (IEC_60559_TYPES_EXT)
131 # define SNANF64X (__builtin_nansf64x (""))
133 #if __HAVE_FLOAT128X && __GLIBC_USE (IEC_60559_TYPES_EXT)
134 # define SNANF128X (__builtin_nansf128x (""))
137 /* Get __GLIBC_FLT_EVAL_METHOD. */
138 #include <bits/flt-eval-method.h>
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
;
176 # error "Unknown __GLIBC_FLT_EVAL_METHOD"
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>
192 # if __FP_LOGB0_IS_MIN
193 # define FP_ILOGB0 (-2147483647 - 1)
195 # define FP_ILOGB0 (-2147483647)
197 # if __FP_LOGBNAN_IS_MIN
198 # define FP_ILOGBNAN (-2147483647 - 1)
200 # define FP_ILOGBNAN 2147483647
203 #if __GLIBC_USE (IEC_60559_BFP_EXT)
204 # if __WORDSIZE == 32
205 # define __FP_LONG_MAX 0x7fffffffL
207 # define __FP_LONG_MAX 0x7fffffffffffffffL
209 # if __FP_LOGB0_IS_MIN
210 # define FP_LLOGB0 (-__FP_LONG_MAX - 1)
212 # define FP_LLOGB0 (-__FP_LONG_MAX)
214 # if __FP_LOGBNAN_IS_MIN
215 # define FP_LLOGBNAN (-__FP_LONG_MAX - 1)
217 # define FP_LLOGBNAN __FP_LONG_MAX
221 /* Get the architecture specific values describing the floating-point
222 evaluation. The following symbols will get defined:
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. */
240 # define FP_INT_UPWARD 0
243 # define FP_INT_DOWNWARD 1
246 # define FP_INT_TOWARDZERO 2
248 FP_INT_TONEARESTFROMZERO
=
249 # define FP_INT_TONEARESTFROMZERO 3
250 FP_INT_TONEARESTFROMZERO
,
252 # define FP_INT_TONEAREST 4
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>
292 #undef __MATH_PRECNAME
293 #undef __MATH_DECLARING_DOUBLE
294 #undef __MATH_DECLARING_FLOATN
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>
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
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
),
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__
));
334 # define __MATHDECL_2(type, function,suffix, args, alias) \
335 extern type __REDIRECT_NTH(__MATH_PRECNAME(function,suffix), \
337 # define __MATHDECL_1(type, function,suffix, args) \
338 __MATHDECL_2(type, function,suffix, args, __CONCAT(function,suffix))
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>
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
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>
371 # if __GLIBC_USE (IEC_60559_TYPES_EXT)
372 # include <bits/mathcalls.h>
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>
388 # if __GLIBC_USE (IEC_60559_TYPES_EXT)
389 # include <bits/mathcalls.h>
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>
405 # if __GLIBC_USE (IEC_60559_TYPES_EXT)
406 # include <bits/mathcalls.h>
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>
422 # if __GLIBC_USE (IEC_60559_TYPES_EXT)
423 # include <bits/mathcalls.h>
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>
439 # if __GLIBC_USE (IEC_60559_TYPES_EXT)
440 # include <bits/mathcalls.h>
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>
456 # if __GLIBC_USE (IEC_60559_TYPES_EXT)
457 # include <bits/mathcalls.h>
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>
473 # if __GLIBC_USE (IEC_60559_TYPES_EXT)
474 # include <bits/mathcalls.h>
477 # undef __MATH_PRECNAME
478 # undef __MATH_DECLARING_DOUBLE
479 # undef __MATH_DECLARING_FLOATN
480 #endif /* __HAVE_DISTINCT_FLOAT128X || (__HAVE_FLOAT128X && !_LIBC). */
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, \
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>
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)
517 # include <bits/mathcalls-narrow.h>
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)
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)
537 # include <bits/mathcalls-narrow.h>
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)
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>
559 # undef __MATHCALL_NAME
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>
569 # undef __MATHCALL_NAME
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>
579 # undef __MATHCALL_NAME
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>
589 # undef __MATHCALL_NAME
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>
599 # undef __MATHCALL_NAME
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>
609 # undef __MATHCALL_NAME
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>
619 # undef __MATHCALL_NAME
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>
629 # undef __MATHCALL_NAME
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>
639 # undef __MATHCALL_NAME
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>
649 # undef __MATHCALL_NAME
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>
659 # undef __MATHCALL_NAME
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>
669 # undef __MATHCALL_NAME
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>
679 # undef __MATHCALL_NAME
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>
689 # undef __MATHCALL_NAME
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>
699 # undef __MATHCALL_NAME
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>
709 # undef __MATHCALL_NAME
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>
719 # undef __MATHCALL_NAME
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>
729 # undef __MATHCALL_NAME
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>
739 # undef __MATHCALL_NAME
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>
749 # undef __MATHCALL_NAME
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>
759 # undef __MATHCALL_NAME
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'. */
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>."
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."
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,
805 # define __MATH_TG_F32(FUNC, ARGS)
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,
811 # define __MATH_TG_F64X(FUNC, ARGS) _Float64x: FUNC ## f128 ARGS,
814 # define __MATH_TG_F64X(FUNC, ARGS)
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)
825 # if __HAVE_FLOATN_NOT_TYPEDEF
826 # error "Non-typedef _FloatN but no _Generic."
828 # define __MATH_TG(TG_ARG, FUNC, ARGS) \
829 __builtin_choose_expr \
830 (__builtin_types_compatible_p (__typeof (TG_ARG), float), \
832 __builtin_choose_expr \
833 (__builtin_types_compatible_p (__typeof (TG_ARG), double), \
835 __builtin_choose_expr \
836 (__builtin_types_compatible_p (__typeof (TG_ARG), long double), \
841 # define __MATH_TG(TG_ARG, FUNC, ARGS) \
842 (sizeof (TG_ARG) == sizeof (float) \
844 : sizeof (TG_ARG) == sizeof (double) \
849 /* ISO C99 defines some generic macros which work on any data type. */
852 /* All floating-point numbers can be put in one of these categories. */
859 # define FP_INFINITE 1
865 # define FP_SUBNORMAL 3
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)
888 # define fpclassify(x) __MATH_TG ((x), __fpclassify, (x))
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))
906 # define signbit(x) __MATH_TG ((x), __signbit, (x))
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)
913 # define isfinite(x) __MATH_TG ((x), __finite, (x))
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)
920 # define isnormal(x) (fpclassify (x) == FP_NORMAL)
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)
928 # define isnan(x) __MATH_TG ((x), __isnan, (x))
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). */
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)
945 # define isinf(x) __MATH_TG ((x), __isinf, (x))
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)
962 # define math_errhandling (MATH_ERRNO | MATH_ERREXCEPT)
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. */
972 # define issignaling(x) __MATH_TG ((x), __issignaling, (x))
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
981 inline int issignaling (float __val
) { return __issignalingf (__val
); }
982 inline int issignaling (double __val
) { return __issignaling (__val
); }
984 issignaling (long double __val
)
986 # ifdef __NO_LONG_DOUBLE_MATH
987 return __issignaling (__val
);
989 return __issignalingl (__val
);
992 # if __HAVE_FLOAT128_UNLIKE_LDBL
993 /* When using an IEEE 128-bit long double, _Float128 is defined as long double
995 inline int issignaling (_Float128 __val
) { return __issignalingf128 (__val
); }
1000 /* Return nonzero value if X is subnormal. */
1001 # define issubnormal(x) (fpclassify (x) == FP_SUBNORMAL)
1003 /* Return nonzero value if X is zero. */
1004 # ifndef __cplusplus
1005 # ifdef __SUPPORT_SNAN__
1006 # define iszero(x) (fpclassify (x) == FP_ZERO)
1008 # define iszero(x) (((__typeof (x)) (x)) == 0)
1010 # else /* __cplusplus */
1012 # ifdef __SUPPORT_SNAN__
1014 iszero (float __val
)
1016 return __fpclassifyf (__val
) == FP_ZERO
;
1019 iszero (double __val
)
1021 return __fpclassify (__val
) == FP_ZERO
;
1024 iszero (long double __val
)
1026 # ifdef __NO_LONG_DOUBLE_MATH
1027 return __fpclassify (__val
) == FP_ZERO
;
1029 return __fpclassifyl (__val
) == FP_ZERO
;
1032 # if __HAVE_FLOAT128_UNLIKE_LDBL
1033 /* When using an IEEE 128-bit long double, _Float128 is defined as long double
1036 iszero (_Float128 __val
)
1038 return __fpclassifyf128 (__val
) == FP_ZERO
;
1042 template <class __T
> inline bool
1049 # endif /* __cplusplus */
1050 #endif /* Use IEC_60559_BFP_EXT. */
1053 /* X/Open wants another strange constant. */
1054 # define MAXFLOAT 3.40282347e+38F
1058 /* Some useful constants. */
1059 #if defined __USE_MISC || defined __USE_XOPEN
1060 # define M_E 2.7182818284590452354 /* e */
1061 # define M_LOG2E 1.4426950408889634074 /* log_2 e */
1062 # define M_LOG10E 0.43429448190325182765 /* log_10 e */
1063 # define M_LN2 0.69314718055994530942 /* log_e 2 */
1064 # define M_LN10 2.30258509299404568402 /* log_e 10 */
1065 # define M_PI 3.14159265358979323846 /* pi */
1066 # define M_PI_2 1.57079632679489661923 /* pi/2 */
1067 # define M_PI_4 0.78539816339744830962 /* pi/4 */
1068 # define M_1_PI 0.31830988618379067154 /* 1/pi */
1069 # define M_2_PI 0.63661977236758134308 /* 2/pi */
1070 # define M_2_SQRTPI 1.12837916709551257390 /* 2/sqrt(pi) */
1071 # define M_SQRT2 1.41421356237309504880 /* sqrt(2) */
1072 # define M_SQRT1_2 0.70710678118654752440 /* 1/sqrt(2) */
1075 /* The above constants are not adequate for computation using `long double's.
1076 Therefore we provide as an extension constants with similar names as a
1077 GNU extension. Provide enough digits for the 128-bit IEEE quad. */
1079 # define M_El 2.718281828459045235360287471352662498L /* e */
1080 # define M_LOG2El 1.442695040888963407359924681001892137L /* log_2 e */
1081 # define M_LOG10El 0.434294481903251827651128918916605082L /* log_10 e */
1082 # define M_LN2l 0.693147180559945309417232121458176568L /* log_e 2 */
1083 # define M_LN10l 2.302585092994045684017991454684364208L /* log_e 10 */
1084 # define M_PIl 3.141592653589793238462643383279502884L /* pi */
1085 # define M_PI_2l 1.570796326794896619231321691639751442L /* pi/2 */
1086 # define M_PI_4l 0.785398163397448309615660845819875721L /* pi/4 */
1087 # define M_1_PIl 0.318309886183790671537767526745028724L /* 1/pi */
1088 # define M_2_PIl 0.636619772367581343075535053490057448L /* 2/pi */
1089 # define M_2_SQRTPIl 1.128379167095512573896158903121545172L /* 2/sqrt(pi) */
1090 # define M_SQRT2l 1.414213562373095048801688724209698079L /* sqrt(2) */
1091 # define M_SQRT1_2l 0.707106781186547524400844362104849039L /* 1/sqrt(2) */
1094 #if __HAVE_FLOAT16 && defined __USE_GNU
1095 # define M_Ef16 __f16 (2.718281828459045235360287471352662498) /* e */
1096 # define M_LOG2Ef16 __f16 (1.442695040888963407359924681001892137) /* log_2 e */
1097 # define M_LOG10Ef16 __f16 (0.434294481903251827651128918916605082) /* log_10 e */
1098 # define M_LN2f16 __f16 (0.693147180559945309417232121458176568) /* log_e 2 */
1099 # define M_LN10f16 __f16 (2.302585092994045684017991454684364208) /* log_e 10 */
1100 # define M_PIf16 __f16 (3.141592653589793238462643383279502884) /* pi */
1101 # define M_PI_2f16 __f16 (1.570796326794896619231321691639751442) /* pi/2 */
1102 # define M_PI_4f16 __f16 (0.785398163397448309615660845819875721) /* pi/4 */
1103 # define M_1_PIf16 __f16 (0.318309886183790671537767526745028724) /* 1/pi */
1104 # define M_2_PIf16 __f16 (0.636619772367581343075535053490057448) /* 2/pi */
1105 # define M_2_SQRTPIf16 __f16 (1.128379167095512573896158903121545172) /* 2/sqrt(pi) */
1106 # define M_SQRT2f16 __f16 (1.414213562373095048801688724209698079) /* sqrt(2) */
1107 # define M_SQRT1_2f16 __f16 (0.707106781186547524400844362104849039) /* 1/sqrt(2) */
1110 #if __HAVE_FLOAT32 && defined __USE_GNU
1111 # define M_Ef32 __f32 (2.718281828459045235360287471352662498) /* e */
1112 # define M_LOG2Ef32 __f32 (1.442695040888963407359924681001892137) /* log_2 e */
1113 # define M_LOG10Ef32 __f32 (0.434294481903251827651128918916605082) /* log_10 e */
1114 # define M_LN2f32 __f32 (0.693147180559945309417232121458176568) /* log_e 2 */
1115 # define M_LN10f32 __f32 (2.302585092994045684017991454684364208) /* log_e 10 */
1116 # define M_PIf32 __f32 (3.141592653589793238462643383279502884) /* pi */
1117 # define M_PI_2f32 __f32 (1.570796326794896619231321691639751442) /* pi/2 */
1118 # define M_PI_4f32 __f32 (0.785398163397448309615660845819875721) /* pi/4 */
1119 # define M_1_PIf32 __f32 (0.318309886183790671537767526745028724) /* 1/pi */
1120 # define M_2_PIf32 __f32 (0.636619772367581343075535053490057448) /* 2/pi */
1121 # define M_2_SQRTPIf32 __f32 (1.128379167095512573896158903121545172) /* 2/sqrt(pi) */
1122 # define M_SQRT2f32 __f32 (1.414213562373095048801688724209698079) /* sqrt(2) */
1123 # define M_SQRT1_2f32 __f32 (0.707106781186547524400844362104849039) /* 1/sqrt(2) */
1126 #if __HAVE_FLOAT64 && defined __USE_GNU
1127 # define M_Ef64 __f64 (2.718281828459045235360287471352662498) /* e */
1128 # define M_LOG2Ef64 __f64 (1.442695040888963407359924681001892137) /* log_2 e */
1129 # define M_LOG10Ef64 __f64 (0.434294481903251827651128918916605082) /* log_10 e */
1130 # define M_LN2f64 __f64 (0.693147180559945309417232121458176568) /* log_e 2 */
1131 # define M_LN10f64 __f64 (2.302585092994045684017991454684364208) /* log_e 10 */
1132 # define M_PIf64 __f64 (3.141592653589793238462643383279502884) /* pi */
1133 # define M_PI_2f64 __f64 (1.570796326794896619231321691639751442) /* pi/2 */
1134 # define M_PI_4f64 __f64 (0.785398163397448309615660845819875721) /* pi/4 */
1135 # define M_1_PIf64 __f64 (0.318309886183790671537767526745028724) /* 1/pi */
1136 # define M_2_PIf64 __f64 (0.636619772367581343075535053490057448) /* 2/pi */
1137 # define M_2_SQRTPIf64 __f64 (1.128379167095512573896158903121545172) /* 2/sqrt(pi) */
1138 # define M_SQRT2f64 __f64 (1.414213562373095048801688724209698079) /* sqrt(2) */
1139 # define M_SQRT1_2f64 __f64 (0.707106781186547524400844362104849039) /* 1/sqrt(2) */
1142 #if __HAVE_FLOAT128 && defined __USE_GNU
1143 # define M_Ef128 __f128 (2.718281828459045235360287471352662498) /* e */
1144 # define M_LOG2Ef128 __f128 (1.442695040888963407359924681001892137) /* log_2 e */
1145 # define M_LOG10Ef128 __f128 (0.434294481903251827651128918916605082) /* log_10 e */
1146 # define M_LN2f128 __f128 (0.693147180559945309417232121458176568) /* log_e 2 */
1147 # define M_LN10f128 __f128 (2.302585092994045684017991454684364208) /* log_e 10 */
1148 # define M_PIf128 __f128 (3.141592653589793238462643383279502884) /* pi */
1149 # define M_PI_2f128 __f128 (1.570796326794896619231321691639751442) /* pi/2 */
1150 # define M_PI_4f128 __f128 (0.785398163397448309615660845819875721) /* pi/4 */
1151 # define M_1_PIf128 __f128 (0.318309886183790671537767526745028724) /* 1/pi */
1152 # define M_2_PIf128 __f128 (0.636619772367581343075535053490057448) /* 2/pi */
1153 # define M_2_SQRTPIf128 __f128 (1.128379167095512573896158903121545172) /* 2/sqrt(pi) */
1154 # define M_SQRT2f128 __f128 (1.414213562373095048801688724209698079) /* sqrt(2) */
1155 # define M_SQRT1_2f128 __f128 (0.707106781186547524400844362104849039) /* 1/sqrt(2) */
1158 #if __HAVE_FLOAT32X && defined __USE_GNU
1159 # define M_Ef32x __f32x (2.718281828459045235360287471352662498) /* e */
1160 # define M_LOG2Ef32x __f32x (1.442695040888963407359924681001892137) /* log_2 e */
1161 # define M_LOG10Ef32x __f32x (0.434294481903251827651128918916605082) /* log_10 e */
1162 # define M_LN2f32x __f32x (0.693147180559945309417232121458176568) /* log_e 2 */
1163 # define M_LN10f32x __f32x (2.302585092994045684017991454684364208) /* log_e 10 */
1164 # define M_PIf32x __f32x (3.141592653589793238462643383279502884) /* pi */
1165 # define M_PI_2f32x __f32x (1.570796326794896619231321691639751442) /* pi/2 */
1166 # define M_PI_4f32x __f32x (0.785398163397448309615660845819875721) /* pi/4 */
1167 # define M_1_PIf32x __f32x (0.318309886183790671537767526745028724) /* 1/pi */
1168 # define M_2_PIf32x __f32x (0.636619772367581343075535053490057448) /* 2/pi */
1169 # define M_2_SQRTPIf32x __f32x (1.128379167095512573896158903121545172) /* 2/sqrt(pi) */
1170 # define M_SQRT2f32x __f32x (1.414213562373095048801688724209698079) /* sqrt(2) */
1171 # define M_SQRT1_2f32x __f32x (0.707106781186547524400844362104849039) /* 1/sqrt(2) */
1174 #if __HAVE_FLOAT64X && defined __USE_GNU
1175 # define M_Ef64x __f64x (2.718281828459045235360287471352662498) /* e */
1176 # define M_LOG2Ef64x __f64x (1.442695040888963407359924681001892137) /* log_2 e */
1177 # define M_LOG10Ef64x __f64x (0.434294481903251827651128918916605082) /* log_10 e */
1178 # define M_LN2f64x __f64x (0.693147180559945309417232121458176568) /* log_e 2 */
1179 # define M_LN10f64x __f64x (2.302585092994045684017991454684364208) /* log_e 10 */
1180 # define M_PIf64x __f64x (3.141592653589793238462643383279502884) /* pi */
1181 # define M_PI_2f64x __f64x (1.570796326794896619231321691639751442) /* pi/2 */
1182 # define M_PI_4f64x __f64x (0.785398163397448309615660845819875721) /* pi/4 */
1183 # define M_1_PIf64x __f64x (0.318309886183790671537767526745028724) /* 1/pi */
1184 # define M_2_PIf64x __f64x (0.636619772367581343075535053490057448) /* 2/pi */
1185 # define M_2_SQRTPIf64x __f64x (1.128379167095512573896158903121545172) /* 2/sqrt(pi) */
1186 # define M_SQRT2f64x __f64x (1.414213562373095048801688724209698079) /* sqrt(2) */
1187 # define M_SQRT1_2f64x __f64x (0.707106781186547524400844362104849039) /* 1/sqrt(2) */
1190 #if __HAVE_FLOAT128X && defined __USE_GNU
1191 # error "M_* values needed for _Float128x"
1194 /* When compiling in strict ISO C compatible mode we must not use the
1195 inline functions since they, among other things, do not set the
1196 `errno' variable correctly. */
1197 #if defined __STRICT_ANSI__ && !defined __NO_MATH_INLINES
1198 # define __NO_MATH_INLINES 1
1202 # if __GNUC_PREREQ (3, 1)
1203 /* ISO C99 defines some macros to compare number while taking care for
1204 unordered numbers. Many FPUs provide special instructions to support
1205 these operations. Generic support in GCC for these as builtins went
1206 in 2.97, but not all cpus added their patterns until 3.1. Therefore
1207 we enable the builtins from 3.1 onwards and use a generic implementation
1209 # define isgreater(x, y) __builtin_isgreater(x, y)
1210 # define isgreaterequal(x, y) __builtin_isgreaterequal(x, y)
1211 # define isless(x, y) __builtin_isless(x, y)
1212 # define islessequal(x, y) __builtin_islessequal(x, y)
1213 # define islessgreater(x, y) __builtin_islessgreater(x, y)
1214 # define isunordered(x, y) __builtin_isunordered(x, y)
1216 # define isgreater(x, y) \
1217 (__extension__ ({ __typeof__ (x) __x = (x); __typeof__ (y) __y = (y); \
1218 !isunordered (__x, __y) && __x > __y; }))
1219 # define isgreaterequal(x, y) \
1220 (__extension__ ({ __typeof__ (x) __x = (x); __typeof__ (y) __y = (y); \
1221 !isunordered (__x, __y) && __x >= __y; }))
1222 # define isless(x, y) \
1223 (__extension__ ({ __typeof__ (x) __x = (x); __typeof__ (y) __y = (y); \
1224 !isunordered (__x, __y) && __x < __y; }))
1225 # define islessequal(x, y) \
1226 (__extension__ ({ __typeof__ (x) __x = (x); __typeof__ (y) __y = (y); \
1227 !isunordered (__x, __y) && __x <= __y; }))
1228 # define islessgreater(x, y) \
1229 (__extension__ ({ __typeof__ (x) __x = (x); __typeof__ (y) __y = (y); \
1230 !isunordered (__x, __y) && __x != __y; }))
1231 /* isunordered must always check both operands first for signaling NaNs. */
1232 # define isunordered(x, y) \
1233 (__extension__ ({ __typeof__ (x) __u = (x); __typeof__ (y) __v = (y); \
1234 __u != __v && (__u != __u || __v != __v); }))
1238 /* Get machine-dependent inline versions (if there are any). */
1239 #ifdef __USE_EXTERN_INLINES
1240 # include <bits/mathinline.h>
1243 /* Define special entry points to use when the compiler got told to
1244 only expect finite results. */
1245 #if defined __FINITE_MATH_ONLY__ && __FINITE_MATH_ONLY__ > 0
1247 /* Include bits/math-finite.h for double. */
1248 # define _Mdouble_ double
1249 # define __MATH_DECLARING_DOUBLE 1
1250 # define __MATH_DECLARING_FLOATN 0
1251 # define __REDIRFROM_X(function, reentrant) \
1252 function ## reentrant
1253 # define __REDIRTO_X(function, reentrant) \
1254 __ ## function ## reentrant ## _finite
1255 # include <bits/math-finite.h>
1257 # undef __MATH_DECLARING_DOUBLE
1258 # undef __MATH_DECLARING_FLOATN
1259 # undef __REDIRFROM_X
1262 /* When __USE_ISOC99 is defined, include math-finite for float and
1263 long double, as well. */
1264 # ifdef __USE_ISOC99
1266 /* Include bits/math-finite.h for float. */
1267 # define _Mdouble_ float
1268 # define __MATH_DECLARING_DOUBLE 0
1269 # define __MATH_DECLARING_FLOATN 0
1270 # define __REDIRFROM_X(function, reentrant) \
1271 function ## f ## reentrant
1272 # define __REDIRTO_X(function, reentrant) \
1273 __ ## function ## f ## reentrant ## _finite
1274 # include <bits/math-finite.h>
1276 # undef __MATH_DECLARING_DOUBLE
1277 # undef __MATH_DECLARING_FLOATN
1278 # undef __REDIRFROM_X
1281 /* Include bits/math-finite.h for long double. */
1282 # ifdef __MATH_DECLARE_LDOUBLE
1283 # define _Mdouble_ long double
1284 # define __MATH_DECLARING_DOUBLE 0
1285 # define __MATH_DECLARING_FLOATN 0
1286 # define __REDIRFROM_X(function, reentrant) \
1287 function ## l ## reentrant
1288 # ifdef __NO_LONG_DOUBLE_MATH
1289 # define __REDIRTO_X(function, reentrant) \
1290 __ ## function ## reentrant ## _finite
1292 # define __REDIRTO_X(function, reentrant) \
1293 __ ## function ## l ## reentrant ## _finite
1295 # include <bits/math-finite.h>
1297 # undef __MATH_DECLARING_DOUBLE
1298 # undef __MATH_DECLARING_FLOATN
1299 # undef __REDIRFROM_X
1303 # endif /* __USE_ISOC99. */
1305 /* Include bits/math-finite.h for _FloatN and _FloatNx. */
1307 # if (__HAVE_DISTINCT_FLOAT16 || (__HAVE_FLOAT16 && !defined _LIBC)) \
1308 && __GLIBC_USE (IEC_60559_TYPES_EXT)
1309 # define _Mdouble_ _Float16
1310 # define __MATH_DECLARING_DOUBLE 0
1311 # define __MATH_DECLARING_FLOATN 1
1312 # define __REDIRFROM_X(function, reentrant) \
1313 function ## f16 ## reentrant
1314 # if __HAVE_DISTINCT_FLOAT16
1315 # define __REDIRTO_X(function, reentrant) \
1316 __ ## function ## f16 ## reentrant ## _finite
1318 # error "non-disinct _Float16"
1320 # include <bits/math-finite.h>
1322 # undef __MATH_DECLARING_DOUBLE
1323 # undef __MATH_DECLARING_FLOATN
1324 # undef __REDIRFROM_X
1328 # if (__HAVE_DISTINCT_FLOAT32 || (__HAVE_FLOAT32 && !defined _LIBC)) \
1329 && __GLIBC_USE (IEC_60559_TYPES_EXT)
1330 # define _Mdouble_ _Float32
1331 # define __MATH_DECLARING_DOUBLE 0
1332 # define __MATH_DECLARING_FLOATN 1
1333 # define __REDIRFROM_X(function, reentrant) \
1334 function ## f32 ## reentrant
1335 # if __HAVE_DISTINCT_FLOAT32
1336 # define __REDIRTO_X(function, reentrant) \
1337 __ ## function ## f32 ## reentrant ## _finite
1339 # define __REDIRTO_X(function, reentrant) \
1340 __ ## function ## f ## reentrant ## _finite
1342 # include <bits/math-finite.h>
1344 # undef __MATH_DECLARING_DOUBLE
1345 # undef __MATH_DECLARING_FLOATN
1346 # undef __REDIRFROM_X
1350 # if (__HAVE_DISTINCT_FLOAT64 || (__HAVE_FLOAT64 && !defined _LIBC)) \
1351 && __GLIBC_USE (IEC_60559_TYPES_EXT)
1352 # define _Mdouble_ _Float64
1353 # define __MATH_DECLARING_DOUBLE 0
1354 # define __MATH_DECLARING_FLOATN 1
1355 # define __REDIRFROM_X(function, reentrant) \
1356 function ## f64 ## reentrant
1357 # if __HAVE_DISTINCT_FLOAT64
1358 # define __REDIRTO_X(function, reentrant) \
1359 __ ## function ## f64 ## reentrant ## _finite
1361 # define __REDIRTO_X(function, reentrant) \
1362 __ ## function ## reentrant ## _finite
1364 # include <bits/math-finite.h>
1366 # undef __MATH_DECLARING_DOUBLE
1367 # undef __MATH_DECLARING_FLOATN
1368 # undef __REDIRFROM_X
1372 # if (__HAVE_DISTINCT_FLOAT128 || (__HAVE_FLOAT128 && !defined _LIBC)) \
1373 && __GLIBC_USE (IEC_60559_TYPES_EXT)
1374 # define _Mdouble_ _Float128
1375 # define __MATH_DECLARING_DOUBLE 0
1376 # define __MATH_DECLARING_FLOATN 1
1377 # define __REDIRFROM_X(function, reentrant) \
1378 function ## f128 ## reentrant
1379 # if __HAVE_DISTINCT_FLOAT128
1380 # define __REDIRTO_X(function, reentrant) \
1381 __ ## function ## f128 ## reentrant ## _finite
1383 # define __REDIRTO_X(function, reentrant) \
1384 __ ## function ## l ## reentrant ## _finite
1386 # include <bits/math-finite.h>
1388 # undef __MATH_DECLARING_DOUBLE
1389 # undef __MATH_DECLARING_FLOATN
1390 # undef __REDIRFROM_X
1394 # if (__HAVE_DISTINCT_FLOAT32X || (__HAVE_FLOAT32X && !defined _LIBC)) \
1395 && __GLIBC_USE (IEC_60559_TYPES_EXT)
1396 # define _Mdouble_ _Float32x
1397 # define __MATH_DECLARING_DOUBLE 0
1398 # define __MATH_DECLARING_FLOATN 1
1399 # define __REDIRFROM_X(function, reentrant) \
1400 function ## f32x ## reentrant
1401 # if __HAVE_DISTINCT_FLOAT32X
1402 # define __REDIRTO_X(function, reentrant) \
1403 __ ## function ## f32x ## reentrant ## _finite
1405 # define __REDIRTO_X(function, reentrant) \
1406 __ ## function ## reentrant ## _finite
1408 # include <bits/math-finite.h>
1410 # undef __MATH_DECLARING_DOUBLE
1411 # undef __MATH_DECLARING_FLOATN
1412 # undef __REDIRFROM_X
1416 # if (__HAVE_DISTINCT_FLOAT64X || (__HAVE_FLOAT64X && !defined _LIBC)) \
1417 && __GLIBC_USE (IEC_60559_TYPES_EXT)
1418 # define _Mdouble_ _Float64x
1419 # define __MATH_DECLARING_DOUBLE 0
1420 # define __MATH_DECLARING_FLOATN 1
1421 # define __REDIRFROM_X(function, reentrant) \
1422 function ## f64x ## reentrant
1423 # if __HAVE_DISTINCT_FLOAT64X
1424 # define __REDIRTO_X(function, reentrant) \
1425 __ ## function ## f64x ## reentrant ## _finite
1426 # elif __HAVE_FLOAT64X_LONG_DOUBLE
1427 # define __REDIRTO_X(function, reentrant) \
1428 __ ## function ## l ## reentrant ## _finite
1430 # define __REDIRTO_X(function, reentrant) \
1431 __ ## function ## f128 ## reentrant ## _finite
1433 # include <bits/math-finite.h>
1435 # undef __MATH_DECLARING_DOUBLE
1436 # undef __MATH_DECLARING_FLOATN
1437 # undef __REDIRFROM_X
1441 # if (__HAVE_DISTINCT_FLOAT128X || (__HAVE_FLOAT128X && !defined _LIBC)) \
1442 && __GLIBC_USE (IEC_60559_TYPES_EXT)
1443 # define _Mdouble_ _Float128x
1444 # define __MATH_DECLARING_DOUBLE 0
1445 # define __MATH_DECLARING_FLOATN 1
1446 # define __REDIRFROM_X(function, reentrant) \
1447 function ## f128x ## reentrant
1448 # if __HAVE_DISTINCT_FLOAT128X
1449 # define __REDIRTO_X(function, reentrant) \
1450 __ ## function ## f128x ## reentrant ## _finite
1452 # error "non-disinct _Float128x"
1454 # include <bits/math-finite.h>
1456 # undef __MATH_DECLARING_DOUBLE
1457 # undef __MATH_DECLARING_FLOATN
1458 # undef __REDIRFROM_X
1462 #endif /* __FINITE_MATH_ONLY__ > 0. */
1464 #if __GLIBC_USE (IEC_60559_BFP_EXT)
1465 /* An expression whose type has the widest of the evaluation formats
1466 of X and Y (which are of floating-point types). */
1467 # if __FLT_EVAL_METHOD__ == 2 || __FLT_EVAL_METHOD__ > 64
1468 # define __MATH_EVAL_FMT2(x, y) ((x) + (y) + 0.0L)
1469 # elif __FLT_EVAL_METHOD__ == 1 || __FLT_EVAL_METHOD__ > 32
1470 # define __MATH_EVAL_FMT2(x, y) ((x) + (y) + 0.0)
1471 # elif __FLT_EVAL_METHOD__ == 0 || __FLT_EVAL_METHOD__ == 32
1472 # define __MATH_EVAL_FMT2(x, y) ((x) + (y) + 0.0f)
1474 # define __MATH_EVAL_FMT2(x, y) ((x) + (y))
1477 /* Return X == Y but raising "invalid" and setting errno if X or Y is
1479 # if !defined __cplusplus || (__cplusplus < 201103L && !defined __GNUC__)
1480 # define iseqsig(x, y) \
1481 __MATH_TG (__MATH_EVAL_FMT2 (x, y), __iseqsig, ((x), (y)))
1483 /* In C++ mode, __MATH_TG cannot be used, because it relies on
1484 __builtin_types_compatible_p, which is a C-only builtin. Moreover,
1485 the comparison macros from ISO C take two floating-point arguments,
1486 which need not have the same type. Choosing what underlying function
1487 to call requires evaluating the formats of the arguments, then
1488 selecting which is wider. The macro __MATH_EVAL_FMT2 provides this
1489 information, however, only the type of the macro expansion is
1490 relevant (actually evaluating the expression would be incorrect).
1491 Thus, the type is used as a template parameter for __iseqsig_type,
1492 which calls the appropriate underlying function. */
1494 template<typename
> struct __iseqsig_type
;
1496 template<> struct __iseqsig_type
<float>
1498 static int __call (float __x
, float __y
) throw ()
1500 return __iseqsigf (__x
, __y
);
1504 template<> struct __iseqsig_type
<double>
1506 static int __call (double __x
, double __y
) throw ()
1508 return __iseqsig (__x
, __y
);
1512 template<> struct __iseqsig_type
<long double>
1514 static int __call (double __x
, double __y
) throw ()
1516 # ifndef __NO_LONG_DOUBLE_MATH
1517 return __iseqsigl (__x
, __y
);
1519 return __iseqsig (__x
, __y
);
1524 # if __HAVE_FLOAT128_UNLIKE_LDBL
1525 /* When using an IEEE 128-bit long double, _Float128 is defined as long double
1527 template<> struct __iseqsig_type
<_Float128
>
1529 static int __call (_Float128 __x
, _Float128 __y
) throw ()
1531 return __iseqsigf128 (__x
, __y
);
1536 template<typename _T1
, typename _T2
>
1538 iseqsig (_T1 __x
, _T2 __y
) throw ()
1540 # if __cplusplus >= 201103L
1541 typedef decltype (__MATH_EVAL_FMT2 (__x
, __y
)) _T3
;
1543 typedef __typeof (__MATH_EVAL_FMT2 (__x
, __y
)) _T3
;
1545 return __iseqsig_type
<_T3
>::__call (__x
, __y
);
1548 } /* extern "C++" */
1549 # endif /* __cplusplus */