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__
436 # define fpclassify(x) __builtin_fpclassify (FP_NAN, FP_INFINITE, \
437 FP_NORMAL, FP_SUBNORMAL, FP_ZERO, x)
439 # define fpclassify(x) __MATH_TG ((x), __fpclassify, (x))
442 /* Return nonzero value if sign of X is negative. */
443 # if __GNUC_PREREQ (6,0)
444 # define signbit(x) __builtin_signbit (x)
445 # elif __GNUC_PREREQ (4,0)
446 # define signbit(x) __MATH_TG ((x), __builtin_signbit, (x))
448 # define signbit(x) __MATH_TG ((x), __signbit, (x))
451 /* Return nonzero value if X is not +-Inf or NaN. */
452 # if __GNUC_PREREQ (4,4) && !defined __SUPPORT_SNAN__
453 # define isfinite(x) __builtin_isfinite (x)
455 # define isfinite(x) __MATH_TG ((x), __finite, (x))
458 /* Return nonzero value if X is neither zero, subnormal, Inf, nor NaN. */
459 # if __GNUC_PREREQ (4,4) && !defined __SUPPORT_SNAN__
460 # define isnormal(x) __builtin_isnormal (x)
462 # define isnormal(x) (fpclassify (x) == FP_NORMAL)
465 /* Return nonzero value if X is a NaN. We could use `fpclassify' but
466 we already have this functions `__isnan' and it is faster. */
467 # if __GNUC_PREREQ (4,4) && !defined __SUPPORT_SNAN__
468 # define isnan(x) __builtin_isnan (x)
470 # define isnan(x) __MATH_TG ((x), __isnan, (x))
473 /* Return nonzero value if X is positive or negative infinity. */
474 # if __HAVE_DISTINCT_FLOAT128 && !__GNUC_PREREQ (7,0) \
475 && !defined __SUPPORT_SNAN__ && !defined __cplusplus
476 /* Since __builtin_isinf_sign is broken for float128 before GCC 7.0,
477 use the helper function, __isinff128, with older compilers. This is
478 only provided for C mode, because in C++ mode, GCC has no support
479 for __builtin_types_compatible_p (and when in C++ mode, this macro is
480 not used anyway, because libstdc++ headers undefine it). */
482 (__builtin_types_compatible_p (__typeof (x), _Float128) \
483 ? __isinff128 (x) : __builtin_isinf_sign (x))
484 # elif __GNUC_PREREQ (4,4) && !defined __SUPPORT_SNAN__
485 # define isinf(x) __builtin_isinf_sign (x)
487 # define isinf(x) __MATH_TG ((x), __isinf, (x))
490 /* Bitmasks for the math_errhandling macro. */
491 # define MATH_ERRNO 1 /* errno set by math functions. */
492 # define MATH_ERREXCEPT 2 /* Exceptions raised by math functions. */
494 /* By default all functions support both errno and exception handling.
495 In gcc's fast math mode and if inline functions are defined this
496 might not be true. */
497 # ifndef __FAST_MATH__
498 # define math_errhandling (MATH_ERRNO | MATH_ERREXCEPT)
501 #endif /* Use ISO C99. */
503 #if __GLIBC_USE (IEC_60559_BFP_EXT)
504 # include <bits/iscanonical.h>
506 /* Return nonzero value if X is a signaling NaN. */
508 # define issignaling(x) __MATH_TG ((x), __issignaling, (x))
510 /* In C++ mode, __MATH_TG cannot be used, because it relies on
511 __builtin_types_compatible_p, which is a C-only builtin. On the
512 other hand, overloading provides the means to distinguish between
513 the floating-point types. The overloading resolution will match
514 the correct parameter (regardless of type qualifiers (i.e.: const
517 inline int issignaling (float __val
) { return __issignalingf (__val
); }
518 inline int issignaling (double __val
) { return __issignaling (__val
); }
520 issignaling (long double __val
)
522 # ifdef __NO_LONG_DOUBLE_MATH
523 return __issignaling (__val
);
525 return __issignalingl (__val
);
528 # if __HAVE_DISTINCT_FLOAT128
529 inline int issignaling (_Float128 __val
) { return __issignalingf128 (__val
); }
534 /* Return nonzero value if X is subnormal. */
535 # define issubnormal(x) (fpclassify (x) == FP_SUBNORMAL)
537 /* Return nonzero value if X is zero. */
539 # ifdef __SUPPORT_SNAN__
540 # define iszero(x) (fpclassify (x) == FP_ZERO)
542 # define iszero(x) (((__typeof (x)) (x)) == 0)
544 # else /* __cplusplus */
546 # ifdef __SUPPORT_SNAN__
550 return __fpclassifyf (__val
) == FP_ZERO
;
553 iszero (double __val
)
555 return __fpclassify (__val
) == FP_ZERO
;
558 iszero (long double __val
)
560 # ifdef __NO_LONG_DOUBLE_MATH
561 return __fpclassify (__val
) == FP_ZERO
;
563 return __fpclassifyl (__val
) == FP_ZERO
;
566 # if __HAVE_DISTINCT_FLOAT128
568 iszero (_Float128 __val
)
570 return __fpclassifyf128 (__val
) == FP_ZERO
;
574 template <class __T
> inline bool
581 # endif /* __cplusplus */
582 #endif /* Use IEC_60559_BFP_EXT. */
585 /* X/Open wants another strange constant. */
586 # define MAXFLOAT 3.40282347e+38F
590 /* Some useful constants. */
591 #if defined __USE_MISC || defined __USE_XOPEN
592 # define M_E 2.7182818284590452354 /* e */
593 # define M_LOG2E 1.4426950408889634074 /* log_2 e */
594 # define M_LOG10E 0.43429448190325182765 /* log_10 e */
595 # define M_LN2 0.69314718055994530942 /* log_e 2 */
596 # define M_LN10 2.30258509299404568402 /* log_e 10 */
597 # define M_PI 3.14159265358979323846 /* pi */
598 # define M_PI_2 1.57079632679489661923 /* pi/2 */
599 # define M_PI_4 0.78539816339744830962 /* pi/4 */
600 # define M_1_PI 0.31830988618379067154 /* 1/pi */
601 # define M_2_PI 0.63661977236758134308 /* 2/pi */
602 # define M_2_SQRTPI 1.12837916709551257390 /* 2/sqrt(pi) */
603 # define M_SQRT2 1.41421356237309504880 /* sqrt(2) */
604 # define M_SQRT1_2 0.70710678118654752440 /* 1/sqrt(2) */
607 /* The above constants are not adequate for computation using `long double's.
608 Therefore we provide as an extension constants with similar names as a
609 GNU extension. Provide enough digits for the 128-bit IEEE quad. */
611 # define M_El 2.718281828459045235360287471352662498L /* e */
612 # define M_LOG2El 1.442695040888963407359924681001892137L /* log_2 e */
613 # define M_LOG10El 0.434294481903251827651128918916605082L /* log_10 e */
614 # define M_LN2l 0.693147180559945309417232121458176568L /* log_e 2 */
615 # define M_LN10l 2.302585092994045684017991454684364208L /* log_e 10 */
616 # define M_PIl 3.141592653589793238462643383279502884L /* pi */
617 # define M_PI_2l 1.570796326794896619231321691639751442L /* pi/2 */
618 # define M_PI_4l 0.785398163397448309615660845819875721L /* pi/4 */
619 # define M_1_PIl 0.318309886183790671537767526745028724L /* 1/pi */
620 # define M_2_PIl 0.636619772367581343075535053490057448L /* 2/pi */
621 # define M_2_SQRTPIl 1.128379167095512573896158903121545172L /* 2/sqrt(pi) */
622 # define M_SQRT2l 1.414213562373095048801688724209698079L /* sqrt(2) */
623 # define M_SQRT1_2l 0.707106781186547524400844362104849039L /* 1/sqrt(2) */
626 #if __HAVE_FLOAT128 && defined __USE_GNU
627 # define M_Ef128 __f128 (2.718281828459045235360287471352662498) /* e */
628 # define M_LOG2Ef128 __f128 (1.442695040888963407359924681001892137) /* log_2 e */
629 # define M_LOG10Ef128 __f128 (0.434294481903251827651128918916605082) /* log_10 e */
630 # define M_LN2f128 __f128 (0.693147180559945309417232121458176568) /* log_e 2 */
631 # define M_LN10f128 __f128 (2.302585092994045684017991454684364208) /* log_e 10 */
632 # define M_PIf128 __f128 (3.141592653589793238462643383279502884) /* pi */
633 # define M_PI_2f128 __f128 (1.570796326794896619231321691639751442) /* pi/2 */
634 # define M_PI_4f128 __f128 (0.785398163397448309615660845819875721) /* pi/4 */
635 # define M_1_PIf128 __f128 (0.318309886183790671537767526745028724) /* 1/pi */
636 # define M_2_PIf128 __f128 (0.636619772367581343075535053490057448) /* 2/pi */
637 # define M_2_SQRTPIf128 __f128 (1.128379167095512573896158903121545172) /* 2/sqrt(pi) */
638 # define M_SQRT2f128 __f128 (1.414213562373095048801688724209698079) /* sqrt(2) */
639 # define M_SQRT1_2f128 __f128 (0.707106781186547524400844362104849039) /* 1/sqrt(2) */
642 /* When compiling in strict ISO C compatible mode we must not use the
643 inline functions since they, among other things, do not set the
644 `errno' variable correctly. */
645 #if defined __STRICT_ANSI__ && !defined __NO_MATH_INLINES
646 # define __NO_MATH_INLINES 1
649 #if defined __USE_ISOC99 && __GNUC_PREREQ(2,97)
650 /* ISO C99 defines some macros to compare number while taking care for
651 unordered numbers. Many FPUs provide special instructions to support
652 these operations. Generic support in GCC for these as builtins went
653 in before 3.0.0, but not all cpus added their patterns. We define
654 versions that use the builtins here, and <bits/mathinline.h> will
655 undef/redefine as appropriate for the specific GCC version in use. */
656 # define isgreater(x, y) __builtin_isgreater(x, y)
657 # define isgreaterequal(x, y) __builtin_isgreaterequal(x, y)
658 # define isless(x, y) __builtin_isless(x, y)
659 # define islessequal(x, y) __builtin_islessequal(x, y)
660 # define islessgreater(x, y) __builtin_islessgreater(x, y)
661 # define isunordered(u, v) __builtin_isunordered(u, v)
664 /* Get machine-dependent inline versions (if there are any). */
665 #ifdef __USE_EXTERN_INLINES
666 # include <bits/mathinline.h>
669 /* Define special entry points to use when the compiler got told to
670 only expect finite results. */
671 #if defined __FINITE_MATH_ONLY__ && __FINITE_MATH_ONLY__ > 0
673 /* Include bits/math-finite.h for double. */
674 # define _Mdouble_ double
675 # define __MATH_DECLARING_DOUBLE 1
676 # define __MATH_DECLARING_FLOATN 0
677 # define __REDIRFROM_X(function, reentrant) \
678 function ## reentrant
679 # define __REDIRTO_X(function, reentrant) \
680 __ ## function ## reentrant ## _finite
681 # include <bits/math-finite.h>
683 # undef __MATH_DECLARING_DOUBLE
684 # undef __MATH_DECLARING_FLOATN
685 # undef __REDIRFROM_X
688 /* When __USE_ISOC99 is defined, include math-finite for float and
689 long double, as well. */
692 /* Include bits/math-finite.h for float. */
693 # define _Mdouble_ float
694 # define __MATH_DECLARING_DOUBLE 0
695 # define __MATH_DECLARING_FLOATN 0
696 # define __REDIRFROM_X(function, reentrant) \
697 function ## f ## reentrant
698 # define __REDIRTO_X(function, reentrant) \
699 __ ## function ## f ## reentrant ## _finite
700 # include <bits/math-finite.h>
702 # undef __MATH_DECLARING_DOUBLE
703 # undef __MATH_DECLARING_FLOATN
704 # undef __REDIRFROM_X
707 /* Include bits/math-finite.h for long double. */
708 # ifdef __MATH_DECLARE_LDOUBLE
709 # define _Mdouble_ long double
710 # define __MATH_DECLARING_DOUBLE 0
711 # define __MATH_DECLARING_FLOATN 0
712 # define __REDIRFROM_X(function, reentrant) \
713 function ## l ## reentrant
714 # ifdef __NO_LONG_DOUBLE_MATH
715 # define __REDIRTO_X(function, reentrant) \
716 __ ## function ## reentrant ## _finite
718 # define __REDIRTO_X(function, reentrant) \
719 __ ## function ## l ## reentrant ## _finite
721 # include <bits/math-finite.h>
723 # undef __MATH_DECLARING_DOUBLE
724 # undef __MATH_DECLARING_FLOATN
725 # undef __REDIRFROM_X
729 # endif /* __USE_ISOC99. */
731 /* Include bits/math-finite.h for float128. */
732 # if (__HAVE_DISTINCT_FLOAT128 || (__HAVE_FLOAT128 && !defined _LIBC)) \
733 && __GLIBC_USE (IEC_60559_TYPES_EXT)
734 # define _Mdouble_ _Float128
735 # define __MATH_DECLARING_DOUBLE 0
736 # define __MATH_DECLARING_FLOATN 1
737 # define __REDIRFROM_X(function, reentrant) \
738 function ## f128 ## reentrant
739 # if __HAVE_DISTINCT_FLOAT128
740 # define __REDIRTO_X(function, reentrant) \
741 __ ## function ## f128 ## reentrant ## _finite
743 # define __REDIRTO_X(function, reentrant) \
744 __ ## function ## l ## reentrant ## _finite
746 # include <bits/math-finite.h>
748 # undef __MATH_DECLARING_DOUBLE
749 # undef __MATH_DECLARING_FLOATN
750 # undef __REDIRFROM_X
753 #endif /* __FINITE_MATH_ONLY__ > 0. */
756 /* If we've still got undefined comparison macros, provide defaults. */
758 /* Return nonzero value if X is greater than Y. */
760 # define isgreater(x, y) \
762 ({ __typeof__(x) __x = (x); __typeof__(y) __y = (y); \
763 !isunordered (__x, __y) && __x > __y; }))
766 /* Return nonzero value if X is greater than or equal to Y. */
767 # ifndef isgreaterequal
768 # define isgreaterequal(x, y) \
770 ({ __typeof__(x) __x = (x); __typeof__(y) __y = (y); \
771 !isunordered (__x, __y) && __x >= __y; }))
774 /* Return nonzero value if X is less than Y. */
776 # define isless(x, y) \
778 ({ __typeof__(x) __x = (x); __typeof__(y) __y = (y); \
779 !isunordered (__x, __y) && __x < __y; }))
782 /* Return nonzero value if X is less than or equal to Y. */
784 # define islessequal(x, y) \
786 ({ __typeof__(x) __x = (x); __typeof__(y) __y = (y); \
787 !isunordered (__x, __y) && __x <= __y; }))
790 /* Return nonzero value if either X is less than Y or Y is less than X. */
791 # ifndef islessgreater
792 # define islessgreater(x, y) \
794 ({ __typeof__(x) __x = (x); __typeof__(y) __y = (y); \
795 !isunordered (__x, __y) && (__x < __y || __y < __x); }))
798 /* Return nonzero value if arguments are unordered. */
800 # define isunordered(u, v) \
802 ({ __typeof__(u) __u = (u); __typeof__(v) __v = (v); \
803 fpclassify (__u) == FP_NAN || fpclassify (__v) == FP_NAN; }))
808 #if __GLIBC_USE (IEC_60559_BFP_EXT)
809 /* An expression whose type has the widest of the evaluation formats
810 of X and Y (which are of floating-point types). */
811 # if __FLT_EVAL_METHOD__ == 2 || __FLT_EVAL_METHOD__ > 64
812 # define __MATH_EVAL_FMT2(x, y) ((x) + (y) + 0.0L)
813 # elif __FLT_EVAL_METHOD__ == 1 || __FLT_EVAL_METHOD__ > 32
814 # define __MATH_EVAL_FMT2(x, y) ((x) + (y) + 0.0)
816 # define __MATH_EVAL_FMT2(x, y) ((x) + (y))
819 /* Return X == Y but raising "invalid" and setting errno if X or Y is
821 # define iseqsig(x, y) \
822 __MATH_TG (__MATH_EVAL_FMT2 (x, y), __iseqsig, ((x), (y)))