1 /* Declarations for math functions.
2 Copyright (C) 1991-2017 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_FLOAT128 && __GLIBC_USE (IEC_60559_TYPES_EXT)
67 # define HUGE_VAL_F128 (__builtin_huge_valf128 ())
71 /* IEEE positive infinity. */
72 # if __GNUC_PREREQ (3, 3)
73 # define INFINITY (__builtin_inff ())
75 # define INFINITY HUGE_VALF
78 /* IEEE Not A Number. */
79 # if __GNUC_PREREQ (3, 3)
80 # define NAN (__builtin_nanf (""))
82 /* This will raise an "invalid" exception outside static initializers,
83 but is the best that can be done in ISO C while remaining a
84 constant expression. */
85 # define NAN (0.0f / 0.0f)
87 #endif /* __USE_ISOC99 */
89 #if __GLIBC_USE (IEC_60559_BFP_EXT)
90 /* Signaling NaN macros, if supported. */
91 # if __GNUC_PREREQ (3, 3)
92 # define SNANF (__builtin_nansf (""))
93 # define SNAN (__builtin_nans (""))
94 # define SNANL (__builtin_nansl (""))
97 #if __HAVE_FLOAT128 && __GLIBC_USE (IEC_60559_TYPES_EXT)
98 # define SNANF128 (__builtin_nansf128 (""))
101 /* Get __GLIBC_FLT_EVAL_METHOD. */
102 #include <bits/flt-eval-method.h>
105 /* Define the following typedefs.
107 float_t floating-point type at least as wide as `float' used
108 to evaluate `float' expressions
109 double_t floating-point type at least as wide as `double' used
110 to evaluate `double' expressions
112 # if __GLIBC_FLT_EVAL_METHOD == 0 || __GLIBC_FLT_EVAL_METHOD == 16
113 typedef float float_t
;
114 typedef double double_t
;
115 # elif __GLIBC_FLT_EVAL_METHOD == 1
116 typedef double float_t
;
117 typedef double double_t
;
118 # elif __GLIBC_FLT_EVAL_METHOD == 2
119 typedef long double float_t
;
120 typedef long double double_t
;
121 # elif __GLIBC_FLT_EVAL_METHOD == 32
122 typedef _Float32 float_t
;
123 typedef double double_t
;
124 # elif __GLIBC_FLT_EVAL_METHOD == 33
125 typedef _Float32x float_t
;
126 typedef _Float32x double_t
;
127 # elif __GLIBC_FLT_EVAL_METHOD == 64
128 typedef _Float64 float_t
;
129 typedef _Float64 double_t
;
130 # elif __GLIBC_FLT_EVAL_METHOD == 65
131 typedef _Float64x float_t
;
132 typedef _Float64x double_t
;
133 # elif __GLIBC_FLT_EVAL_METHOD == 128
134 typedef _Float128 float_t
;
135 typedef _Float128 double_t
;
136 # elif __GLIBC_FLT_EVAL_METHOD == 129
137 typedef _Float128x float_t
;
138 typedef _Float128x double_t
;
140 # error "Unknown __GLIBC_FLT_EVAL_METHOD"
144 /* Define macros for the return values of ilogb and llogb, based on
145 __FP_LOGB0_IS_MIN and __FP_LOGBNAN_IS_MIN.
147 FP_ILOGB0 Expands to a value returned by `ilogb (0.0)'.
148 FP_ILOGBNAN Expands to a value returned by `ilogb (NAN)'.
149 FP_LLOGB0 Expands to a value returned by `llogb (0.0)'.
150 FP_LLOGBNAN Expands to a value returned by `llogb (NAN)'.
154 #include <bits/fp-logb.h>
156 # if __FP_LOGB0_IS_MIN
157 # define FP_ILOGB0 (-2147483647 - 1)
159 # define FP_ILOGB0 (-2147483647)
161 # if __FP_LOGBNAN_IS_MIN
162 # define FP_ILOGBNAN (-2147483647 - 1)
164 # define FP_ILOGBNAN 2147483647
167 #if __GLIBC_USE (IEC_60559_BFP_EXT)
168 # if __WORDSIZE == 32
169 # define __FP_LONG_MAX 0x7fffffffL
171 # define __FP_LONG_MAX 0x7fffffffffffffffL
173 # if __FP_LOGB0_IS_MIN
174 # define FP_LLOGB0 (-__FP_LONG_MAX - 1)
176 # define FP_LLOGB0 (-__FP_LONG_MAX)
178 # if __FP_LOGBNAN_IS_MIN
179 # define FP_LLOGBNAN (-__FP_LONG_MAX - 1)
181 # define FP_LLOGBNAN __FP_LONG_MAX
185 /* Get the architecture specific values describing the floating-point
186 evaluation. The following symbols will get defined:
191 If defined it indicates that the `fma' function
192 generally executes about as fast as a multiply and an add.
193 This macro is defined only iff the `fma' function is
194 implemented directly with a hardware multiply-add instructions.
197 #include <bits/fp-fast.h>
199 #if __GLIBC_USE (IEC_60559_BFP_EXT)
200 /* Rounding direction macros for fromfp functions. */
204 # define FP_INT_UPWARD 0
207 # define FP_INT_DOWNWARD 1
210 # define FP_INT_TOWARDZERO 2
212 FP_INT_TONEARESTFROMZERO
=
213 # define FP_INT_TONEARESTFROMZERO 3
214 FP_INT_TONEARESTFROMZERO
,
216 # define FP_INT_TONEAREST 4
221 /* The file <bits/mathcalls.h> contains the prototypes for all the
222 actual math functions. These macros are used for those prototypes,
223 so we can easily declare each function as both `name' and `__name',
224 and can declare the float versions `namef' and `__namef'. */
226 #define __SIMD_DECL(function) __CONCAT (__DECL_SIMD_, function)
228 #define __MATHCALL_VEC(function, suffix, args) \
229 __SIMD_DECL (__MATH_PRECNAME (function, suffix)) \
230 __MATHCALL (function, suffix, args)
232 #define __MATHDECL_VEC(type, function,suffix, args) \
233 __SIMD_DECL (__MATH_PRECNAME (function, suffix)) \
234 __MATHDECL(type, function,suffix, args)
236 #define __MATHCALL(function,suffix, args) \
237 __MATHDECL (_Mdouble_,function,suffix, args)
238 #define __MATHDECL(type, function,suffix, args) \
239 __MATHDECL_1(type, function,suffix, args); \
240 __MATHDECL_1(type, __CONCAT(__,function),suffix, args)
241 #define __MATHCALLX(function,suffix, args, attrib) \
242 __MATHDECLX (_Mdouble_,function,suffix, args, attrib)
243 #define __MATHDECLX(type, function,suffix, args, attrib) \
244 __MATHDECL_1(type, function,suffix, args) __attribute__ (attrib); \
245 __MATHDECL_1(type, __CONCAT(__,function),suffix, args) __attribute__ (attrib)
246 #define __MATHDECL_1(type, function,suffix, args) \
247 extern type __MATH_PRECNAME(function,suffix) args __THROW
249 #define _Mdouble_ double
250 #define __MATH_PRECNAME(name,r) __CONCAT(name,r)
251 #define __MATH_DECLARING_DOUBLE 1
252 #define __MATH_DECLARING_FLOATN 0
253 #include <bits/mathcalls-helper-functions.h>
254 #include <bits/mathcalls.h>
256 #undef __MATH_PRECNAME
257 #undef __MATH_DECLARING_DOUBLE
258 #undef __MATH_DECLARING_FLOATN
263 /* Include the file of declarations again, this time using `float'
264 instead of `double' and appending f to each function name. */
267 # define _Mfloat_ float
269 # define _Mdouble_ _Mfloat_
270 # define __MATH_PRECNAME(name,r) name##f##r
271 # define __MATH_DECLARING_DOUBLE 0
272 # define __MATH_DECLARING_FLOATN 0
273 # include <bits/mathcalls-helper-functions.h>
274 # include <bits/mathcalls.h>
276 # undef __MATH_PRECNAME
277 # undef __MATH_DECLARING_DOUBLE
278 # undef __MATH_DECLARING_FLOATN
280 # if !(defined __NO_LONG_DOUBLE_MATH && defined _LIBC) \
281 || defined __LDBL_COMPAT \
282 || defined _LIBC_TEST
283 # ifdef __LDBL_COMPAT
286 extern float __nldbl_nexttowardf (float __x
, long double __y
)
287 __THROW
__attribute__ ((__const__
));
288 # ifdef __REDIRECT_NTH
289 extern float __REDIRECT_NTH (nexttowardf
, (float __x
, long double __y
),
291 __attribute__ ((__const__
));
292 extern double __REDIRECT_NTH (nexttoward
, (double __x
, long double __y
),
293 nextafter
) __attribute__ ((__const__
));
294 extern long double __REDIRECT_NTH (nexttowardl
,
295 (long double __x
, long double __y
),
296 nextafter
) __attribute__ ((__const__
));
301 # define __MATHDECL_2(type, function,suffix, args, alias) \
302 extern type __REDIRECT_NTH(__MATH_PRECNAME(function,suffix), \
304 # define __MATHDECL_1(type, function,suffix, args) \
305 __MATHDECL_2(type, function,suffix, args, __CONCAT(function,suffix))
308 /* Include the file of declarations again, this time using `long double'
309 instead of `double' and appending l to each function name. */
311 # ifndef _Mlong_double_
312 # define _Mlong_double_ long double
314 # define _Mdouble_ _Mlong_double_
315 # define __MATH_PRECNAME(name,r) name##l##r
316 # define __MATH_DECLARING_DOUBLE 0
317 # define __MATH_DECLARING_FLOATN 0
318 # define __MATH_DECLARE_LDOUBLE 1
319 # include <bits/mathcalls-helper-functions.h>
320 # include <bits/mathcalls.h>
322 # undef __MATH_PRECNAME
323 # undef __MATH_DECLARING_DOUBLE
324 # undef __MATH_DECLARING_FLOATN
326 # endif /* !(__NO_LONG_DOUBLE_MATH && _LIBC) || __LDBL_COMPAT */
328 #endif /* Use ISO C99. */
330 /* Include the file of declarations again, this time using `_Float128'
331 instead of `double' and appending f128 to each function name. */
333 #if __HAVE_DISTINCT_FLOAT128 || (__HAVE_FLOAT128 && !defined _LIBC)
335 # define _Mfloat128_ _Float128
337 # define _Mdouble_ _Mfloat128_
338 # define __MATH_PRECNAME(name,r) name##f128##r
339 # define __MATH_DECLARING_DOUBLE 0
340 # define __MATH_DECLARING_FLOATN 1
341 # if __HAVE_DISTINCT_FLOAT128
342 # include <bits/mathcalls-helper-functions.h>
344 # if __GLIBC_USE (IEC_60559_TYPES_EXT)
345 # include <bits/mathcalls.h>
348 # undef __MATH_PRECNAME
349 # undef __MATH_DECLARING_DOUBLE
350 # undef __MATH_DECLARING_FLOATN
351 #endif /* __HAVE_DISTINCT_FLOAT128. */
358 #if defined __USE_MISC || defined __USE_XOPEN
359 /* This variable is used by `gamma' and `lgamma'. */
364 /* Depending on the type of TG_ARG, call an appropriately suffixed
365 version of FUNC with arguments (including parentheses) ARGS.
366 Suffixed functions may not exist for long double if it has the same
367 format as double, or for other types with the same format as float,
368 double or long double. The behavior is undefined if the argument
369 does not have a real floating type. The definition may use a
370 conditional expression, so all suffixed versions of FUNC must
371 return the same type (FUNC may include a cast if necessary rather
372 than being a single identifier). */
373 #ifdef __NO_LONG_DOUBLE_MATH
374 # define __MATH_TG(TG_ARG, FUNC, ARGS) \
375 (sizeof (TG_ARG) == sizeof (float) ? FUNC ## f ARGS : FUNC ARGS)
376 #elif __HAVE_DISTINCT_FLOAT128
377 # if __HAVE_GENERIC_SELECTION
378 # define __MATH_TG(TG_ARG, FUNC, ARGS) \
379 _Generic ((TG_ARG), \
380 float: FUNC ## f ARGS, \
381 default: FUNC ARGS, \
382 long double: FUNC ## l ARGS, \
383 _Float128: FUNC ## f128 ARGS)
385 # define __MATH_TG(TG_ARG, FUNC, ARGS) \
386 __builtin_choose_expr \
387 (__builtin_types_compatible_p (__typeof (TG_ARG), float), \
389 __builtin_choose_expr \
390 (__builtin_types_compatible_p (__typeof (TG_ARG), double), \
392 __builtin_choose_expr \
393 (__builtin_types_compatible_p (__typeof (TG_ARG), long double), \
398 # define __MATH_TG(TG_ARG, FUNC, ARGS) \
399 (sizeof (TG_ARG) == sizeof (float) \
401 : sizeof (TG_ARG) == sizeof (double) \
406 /* ISO C99 defines some generic macros which work on any data type. */
409 /* All floating-point numbers can be put in one of these categories. */
416 # define FP_INFINITE 1
422 # define FP_SUBNORMAL 3
429 /* GCC bug 66462 means we cannot use the math builtins with -fsignaling-nan,
430 so disable builtins if this is enabled. When fixed in a newer GCC,
431 the __SUPPORT_SNAN__ check may be skipped for those versions. */
433 /* Return number of classification appropriate for X. */
434 # if __GNUC_PREREQ (4,4) && !defined __SUPPORT_SNAN__ \
435 && (!defined __OPTIMIZE_SIZE__ || defined __cplusplus)
436 /* The check for __cplusplus allows the use of the builtin, even
437 when optimization for size is on. This is provided for
438 libstdc++, only to let its configure test work when it is built
439 with -Os. No further use of this definition of fpclassify is
440 expected in C++ mode, since libstdc++ provides its own version
441 of fpclassify in cmath (which undefines fpclassify). */
442 # define fpclassify(x) __builtin_fpclassify (FP_NAN, FP_INFINITE, \
443 FP_NORMAL, FP_SUBNORMAL, FP_ZERO, x)
445 # define fpclassify(x) __MATH_TG ((x), __fpclassify, (x))
448 /* Return nonzero value if sign of X is negative. */
449 # if __GNUC_PREREQ (6,0)
450 # define signbit(x) __builtin_signbit (x)
451 # elif defined __cplusplus
452 /* In C++ mode, __MATH_TG cannot be used, because it relies on
453 __builtin_types_compatible_p, which is a C-only builtin.
454 The check for __cplusplus allows the use of the builtin instead of
455 __MATH_TG. This is provided for libstdc++, only to let its configure
456 test work. No further use of this definition of signbit is expected
457 in C++ mode, since libstdc++ provides its own version of signbit
458 in cmath (which undefines signbit). */
459 # define signbit(x) __builtin_signbitl (x)
460 # elif __GNUC_PREREQ (4,0)
461 # define signbit(x) __MATH_TG ((x), __builtin_signbit, (x))
463 # define signbit(x) __MATH_TG ((x), __signbit, (x))
466 /* Return nonzero value if X is not +-Inf or NaN. */
467 # if __GNUC_PREREQ (4,4) && !defined __SUPPORT_SNAN__
468 # define isfinite(x) __builtin_isfinite (x)
470 # define isfinite(x) __MATH_TG ((x), __finite, (x))
473 /* Return nonzero value if X is neither zero, subnormal, Inf, nor NaN. */
474 # if __GNUC_PREREQ (4,4) && !defined __SUPPORT_SNAN__
475 # define isnormal(x) __builtin_isnormal (x)
477 # define isnormal(x) (fpclassify (x) == FP_NORMAL)
480 /* Return nonzero value if X is a NaN. We could use `fpclassify' but
481 we already have this functions `__isnan' and it is faster. */
482 # if __GNUC_PREREQ (4,4) && !defined __SUPPORT_SNAN__
483 # define isnan(x) __builtin_isnan (x)
485 # define isnan(x) __MATH_TG ((x), __isnan, (x))
488 /* Return nonzero value if X is positive or negative infinity. */
489 # if __HAVE_DISTINCT_FLOAT128 && !__GNUC_PREREQ (7,0) \
490 && !defined __SUPPORT_SNAN__ && !defined __cplusplus
491 /* Since __builtin_isinf_sign is broken for float128 before GCC 7.0,
492 use the helper function, __isinff128, with older compilers. This is
493 only provided for C mode, because in C++ mode, GCC has no support
494 for __builtin_types_compatible_p (and when in C++ mode, this macro is
495 not used anyway, because libstdc++ headers undefine it). */
497 (__builtin_types_compatible_p (__typeof (x), _Float128) \
498 ? __isinff128 (x) : __builtin_isinf_sign (x))
499 # elif __GNUC_PREREQ (4,4) && !defined __SUPPORT_SNAN__
500 # define isinf(x) __builtin_isinf_sign (x)
502 # define isinf(x) __MATH_TG ((x), __isinf, (x))
505 /* Bitmasks for the math_errhandling macro. */
506 # define MATH_ERRNO 1 /* errno set by math functions. */
507 # define MATH_ERREXCEPT 2 /* Exceptions raised by math functions. */
509 /* By default all functions support both errno and exception handling.
510 In gcc's fast math mode and if inline functions are defined this
511 might not be true. */
512 # ifndef __FAST_MATH__
513 # define math_errhandling (MATH_ERRNO | MATH_ERREXCEPT)
516 #endif /* Use ISO C99. */
518 #if __GLIBC_USE (IEC_60559_BFP_EXT)
519 # include <bits/iscanonical.h>
521 /* Return nonzero value if X is a signaling NaN. */
523 # define issignaling(x) __MATH_TG ((x), __issignaling, (x))
525 /* In C++ mode, __MATH_TG cannot be used, because it relies on
526 __builtin_types_compatible_p, which is a C-only builtin. On the
527 other hand, overloading provides the means to distinguish between
528 the floating-point types. The overloading resolution will match
529 the correct parameter (regardless of type qualifiers (i.e.: const
532 inline int issignaling (float __val
) { return __issignalingf (__val
); }
533 inline int issignaling (double __val
) { return __issignaling (__val
); }
535 issignaling (long double __val
)
537 # ifdef __NO_LONG_DOUBLE_MATH
538 return __issignaling (__val
);
540 return __issignalingl (__val
);
543 # if __HAVE_DISTINCT_FLOAT128
544 inline int issignaling (_Float128 __val
) { return __issignalingf128 (__val
); }
549 /* Return nonzero value if X is subnormal. */
550 # define issubnormal(x) (fpclassify (x) == FP_SUBNORMAL)
552 /* Return nonzero value if X is zero. */
554 # ifdef __SUPPORT_SNAN__
555 # define iszero(x) (fpclassify (x) == FP_ZERO)
557 # define iszero(x) (((__typeof (x)) (x)) == 0)
559 # else /* __cplusplus */
561 # ifdef __SUPPORT_SNAN__
565 return __fpclassifyf (__val
) == FP_ZERO
;
568 iszero (double __val
)
570 return __fpclassify (__val
) == FP_ZERO
;
573 iszero (long double __val
)
575 # ifdef __NO_LONG_DOUBLE_MATH
576 return __fpclassify (__val
) == FP_ZERO
;
578 return __fpclassifyl (__val
) == FP_ZERO
;
581 # if __HAVE_DISTINCT_FLOAT128
583 iszero (_Float128 __val
)
585 return __fpclassifyf128 (__val
) == FP_ZERO
;
589 template <class __T
> inline bool
596 # endif /* __cplusplus */
597 #endif /* Use IEC_60559_BFP_EXT. */
600 /* X/Open wants another strange constant. */
601 # define MAXFLOAT 3.40282347e+38F
605 /* Some useful constants. */
606 #if defined __USE_MISC || defined __USE_XOPEN
607 # define M_E 2.7182818284590452354 /* e */
608 # define M_LOG2E 1.4426950408889634074 /* log_2 e */
609 # define M_LOG10E 0.43429448190325182765 /* log_10 e */
610 # define M_LN2 0.69314718055994530942 /* log_e 2 */
611 # define M_LN10 2.30258509299404568402 /* log_e 10 */
612 # define M_PI 3.14159265358979323846 /* pi */
613 # define M_PI_2 1.57079632679489661923 /* pi/2 */
614 # define M_PI_4 0.78539816339744830962 /* pi/4 */
615 # define M_1_PI 0.31830988618379067154 /* 1/pi */
616 # define M_2_PI 0.63661977236758134308 /* 2/pi */
617 # define M_2_SQRTPI 1.12837916709551257390 /* 2/sqrt(pi) */
618 # define M_SQRT2 1.41421356237309504880 /* sqrt(2) */
619 # define M_SQRT1_2 0.70710678118654752440 /* 1/sqrt(2) */
622 /* The above constants are not adequate for computation using `long double's.
623 Therefore we provide as an extension constants with similar names as a
624 GNU extension. Provide enough digits for the 128-bit IEEE quad. */
626 # define M_El 2.718281828459045235360287471352662498L /* e */
627 # define M_LOG2El 1.442695040888963407359924681001892137L /* log_2 e */
628 # define M_LOG10El 0.434294481903251827651128918916605082L /* log_10 e */
629 # define M_LN2l 0.693147180559945309417232121458176568L /* log_e 2 */
630 # define M_LN10l 2.302585092994045684017991454684364208L /* log_e 10 */
631 # define M_PIl 3.141592653589793238462643383279502884L /* pi */
632 # define M_PI_2l 1.570796326794896619231321691639751442L /* pi/2 */
633 # define M_PI_4l 0.785398163397448309615660845819875721L /* pi/4 */
634 # define M_1_PIl 0.318309886183790671537767526745028724L /* 1/pi */
635 # define M_2_PIl 0.636619772367581343075535053490057448L /* 2/pi */
636 # define M_2_SQRTPIl 1.128379167095512573896158903121545172L /* 2/sqrt(pi) */
637 # define M_SQRT2l 1.414213562373095048801688724209698079L /* sqrt(2) */
638 # define M_SQRT1_2l 0.707106781186547524400844362104849039L /* 1/sqrt(2) */
641 #if __HAVE_FLOAT128 && defined __USE_GNU
642 # define M_Ef128 __f128 (2.718281828459045235360287471352662498) /* e */
643 # define M_LOG2Ef128 __f128 (1.442695040888963407359924681001892137) /* log_2 e */
644 # define M_LOG10Ef128 __f128 (0.434294481903251827651128918916605082) /* log_10 e */
645 # define M_LN2f128 __f128 (0.693147180559945309417232121458176568) /* log_e 2 */
646 # define M_LN10f128 __f128 (2.302585092994045684017991454684364208) /* log_e 10 */
647 # define M_PIf128 __f128 (3.141592653589793238462643383279502884) /* pi */
648 # define M_PI_2f128 __f128 (1.570796326794896619231321691639751442) /* pi/2 */
649 # define M_PI_4f128 __f128 (0.785398163397448309615660845819875721) /* pi/4 */
650 # define M_1_PIf128 __f128 (0.318309886183790671537767526745028724) /* 1/pi */
651 # define M_2_PIf128 __f128 (0.636619772367581343075535053490057448) /* 2/pi */
652 # define M_2_SQRTPIf128 __f128 (1.128379167095512573896158903121545172) /* 2/sqrt(pi) */
653 # define M_SQRT2f128 __f128 (1.414213562373095048801688724209698079) /* sqrt(2) */
654 # define M_SQRT1_2f128 __f128 (0.707106781186547524400844362104849039) /* 1/sqrt(2) */
657 /* When compiling in strict ISO C compatible mode we must not use the
658 inline functions since they, among other things, do not set the
659 `errno' variable correctly. */
660 #if defined __STRICT_ANSI__ && !defined __NO_MATH_INLINES
661 # define __NO_MATH_INLINES 1
665 # if __GNUC_PREREQ (3, 1)
666 /* ISO C99 defines some macros to compare number while taking care for
667 unordered numbers. Many FPUs provide special instructions to support
668 these operations. Generic support in GCC for these as builtins went
669 in 2.97, but not all cpus added their patterns until 3.1. Therefore
670 we enable the builtins from 3.1 onwards and use a generic implementation
672 # define isgreater(x, y) __builtin_isgreater(x, y)
673 # define isgreaterequal(x, y) __builtin_isgreaterequal(x, y)
674 # define isless(x, y) __builtin_isless(x, y)
675 # define islessequal(x, y) __builtin_islessequal(x, y)
676 # define islessgreater(x, y) __builtin_islessgreater(x, y)
677 # define isunordered(x, y) __builtin_isunordered(x, y)
679 # define isgreater(x, y) \
680 (__extension__ ({ __typeof__ (x) __x = (x); __typeof__ (y) __y = (y); \
681 !isunordered (__x, __y) && __x > __y; }))
682 # define isgreaterequal(x, y) \
683 (__extension__ ({ __typeof__ (x) __x = (x); __typeof__ (y) __y = (y); \
684 !isunordered (__x, __y) && __x >= __y; }))
685 # define isless(x, y) \
686 (__extension__ ({ __typeof__ (x) __x = (x); __typeof__ (y) __y = (y); \
687 !isunordered (__x, __y) && __x < __y; }))
688 # define islessequal(x, y) \
689 (__extension__ ({ __typeof__ (x) __x = (x); __typeof__ (y) __y = (y); \
690 !isunordered (__x, __y) && __x <= __y; }))
691 # define islessgreater(x, y) \
692 (__extension__ ({ __typeof__ (x) __x = (x); __typeof__ (y) __y = (y); \
693 !isunordered (__x, __y) && __x != __y; }))
694 /* isunordered must always check both operands first for signaling NaNs. */
695 # define isunordered(x, y) \
696 (__extension__ ({ __typeof__ (x) __u = (x); __typeof__ (y) __v = (y); \
697 __u != __v && (__u != __u || __v != __v); }))
701 /* Get machine-dependent inline versions (if there are any). */
702 #ifdef __USE_EXTERN_INLINES
703 # include <bits/mathinline.h>
706 /* Define special entry points to use when the compiler got told to
707 only expect finite results. */
708 #if defined __FINITE_MATH_ONLY__ && __FINITE_MATH_ONLY__ > 0
710 /* Include bits/math-finite.h for double. */
711 # define _Mdouble_ double
712 # define __MATH_DECLARING_DOUBLE 1
713 # define __MATH_DECLARING_FLOATN 0
714 # define __REDIRFROM_X(function, reentrant) \
715 function ## reentrant
716 # define __REDIRTO_X(function, reentrant) \
717 __ ## function ## reentrant ## _finite
718 # include <bits/math-finite.h>
720 # undef __MATH_DECLARING_DOUBLE
721 # undef __MATH_DECLARING_FLOATN
722 # undef __REDIRFROM_X
725 /* When __USE_ISOC99 is defined, include math-finite for float and
726 long double, as well. */
729 /* Include bits/math-finite.h for float. */
730 # define _Mdouble_ float
731 # define __MATH_DECLARING_DOUBLE 0
732 # define __MATH_DECLARING_FLOATN 0
733 # define __REDIRFROM_X(function, reentrant) \
734 function ## f ## reentrant
735 # define __REDIRTO_X(function, reentrant) \
736 __ ## function ## f ## reentrant ## _finite
737 # include <bits/math-finite.h>
739 # undef __MATH_DECLARING_DOUBLE
740 # undef __MATH_DECLARING_FLOATN
741 # undef __REDIRFROM_X
744 /* Include bits/math-finite.h for long double. */
745 # ifdef __MATH_DECLARE_LDOUBLE
746 # define _Mdouble_ long double
747 # define __MATH_DECLARING_DOUBLE 0
748 # define __MATH_DECLARING_FLOATN 0
749 # define __REDIRFROM_X(function, reentrant) \
750 function ## l ## reentrant
751 # ifdef __NO_LONG_DOUBLE_MATH
752 # define __REDIRTO_X(function, reentrant) \
753 __ ## function ## reentrant ## _finite
755 # define __REDIRTO_X(function, reentrant) \
756 __ ## function ## l ## reentrant ## _finite
758 # include <bits/math-finite.h>
760 # undef __MATH_DECLARING_DOUBLE
761 # undef __MATH_DECLARING_FLOATN
762 # undef __REDIRFROM_X
766 # endif /* __USE_ISOC99. */
768 /* Include bits/math-finite.h for float128. */
769 # if (__HAVE_DISTINCT_FLOAT128 || (__HAVE_FLOAT128 && !defined _LIBC)) \
770 && __GLIBC_USE (IEC_60559_TYPES_EXT)
771 # define _Mdouble_ _Float128
772 # define __MATH_DECLARING_DOUBLE 0
773 # define __MATH_DECLARING_FLOATN 1
774 # define __REDIRFROM_X(function, reentrant) \
775 function ## f128 ## reentrant
776 # if __HAVE_DISTINCT_FLOAT128
777 # define __REDIRTO_X(function, reentrant) \
778 __ ## function ## f128 ## reentrant ## _finite
780 # define __REDIRTO_X(function, reentrant) \
781 __ ## function ## l ## reentrant ## _finite
783 # include <bits/math-finite.h>
785 # undef __MATH_DECLARING_DOUBLE
786 # undef __MATH_DECLARING_FLOATN
787 # undef __REDIRFROM_X
790 #endif /* __FINITE_MATH_ONLY__ > 0. */
792 #if __GLIBC_USE (IEC_60559_BFP_EXT)
793 /* An expression whose type has the widest of the evaluation formats
794 of X and Y (which are of floating-point types). */
795 # if __FLT_EVAL_METHOD__ == 2 || __FLT_EVAL_METHOD__ > 64
796 # define __MATH_EVAL_FMT2(x, y) ((x) + (y) + 0.0L)
797 # elif __FLT_EVAL_METHOD__ == 1 || __FLT_EVAL_METHOD__ > 32
798 # define __MATH_EVAL_FMT2(x, y) ((x) + (y) + 0.0)
800 # define __MATH_EVAL_FMT2(x, y) ((x) + (y))
803 /* Return X == Y but raising "invalid" and setting errno if X or Y is
805 # define iseqsig(x, y) \
806 __MATH_TG (__MATH_EVAL_FMT2 (x, y), __iseqsig, ((x), (y)))