]> git.ipfire.org Git - thirdparty/glibc.git/blob - math/math.h
Simplify C99 isgreater macros
[thirdparty/glibc.git] / math / math.h
1 /* Declarations for math functions.
2 Copyright (C) 1991-2017 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4
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.
9
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.
14
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/>. */
18
19 /*
20 * ISO C99 Standard: 7.12 Mathematics <math.h>
21 */
22
23 #ifndef _MATH_H
24 #define _MATH_H 1
25
26 #define __GLIBC_INTERNAL_STARTING_HEADER_IMPLEMENTATION
27 #include <bits/libc-header-start.h>
28
29 #if defined log && defined __GNUC__
30 # warning A macro called log was already defined when <math.h> was included.
31 # warning This will cause compilation problems.
32 #endif
33
34 __BEGIN_DECLS
35
36 /* Get definitions of __intmax_t and __uintmax_t. */
37 #include <bits/types.h>
38
39 /* Get machine-dependent vector math functions declarations. */
40 #include <bits/math-vector.h>
41
42 /* Gather machine dependent type support. */
43 #include <bits/floatn.h>
44
45 /* Value returned on overflow. With IEEE 754 floating point, this is
46 +Infinity, otherwise the largest representable positive value. */
47 #if __GNUC_PREREQ (3, 3)
48 # define HUGE_VAL (__builtin_huge_val ())
49 #else
50 /* This may provoke compiler warnings, and may not be rounded to
51 +Infinity in all IEEE 754 rounding modes, but is the best that can
52 be done in ISO C while remaining a constant expression. 10,000 is
53 greater than the maximum (decimal) exponent for all supported
54 floating-point formats and widths. */
55 # define HUGE_VAL 1e10000
56 #endif
57 #ifdef __USE_ISOC99
58 # if __GNUC_PREREQ (3, 3)
59 # define HUGE_VALF (__builtin_huge_valf ())
60 # define HUGE_VALL (__builtin_huge_vall ())
61 # else
62 # define HUGE_VALF 1e10000f
63 # define HUGE_VALL 1e10000L
64 # endif
65 #endif
66 #if __HAVE_FLOAT128 && __GLIBC_USE (IEC_60559_TYPES_EXT)
67 # define HUGE_VAL_F128 (__builtin_huge_valf128 ())
68 #endif
69
70 #ifdef __USE_ISOC99
71 /* IEEE positive infinity. */
72 # if __GNUC_PREREQ (3, 3)
73 # define INFINITY (__builtin_inff ())
74 # else
75 # define INFINITY HUGE_VALF
76 # endif
77
78 /* IEEE Not A Number. */
79 # if __GNUC_PREREQ (3, 3)
80 # define NAN (__builtin_nanf (""))
81 # else
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)
86 # endif
87 #endif /* __USE_ISOC99 */
88
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 (""))
95 # endif
96 #endif
97 #if __HAVE_FLOAT128 && __GLIBC_USE (IEC_60559_TYPES_EXT)
98 # define SNANF128 (__builtin_nansf128 (""))
99 #endif
100
101 /* Get __GLIBC_FLT_EVAL_METHOD. */
102 #include <bits/flt-eval-method.h>
103
104 #ifdef __USE_ISOC99
105 /* Define the following typedefs.
106
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
111 */
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;
139 # else
140 # error "Unknown __GLIBC_FLT_EVAL_METHOD"
141 # endif
142 #endif
143
144 /* Define macros for the return values of ilogb and llogb, based on
145 __FP_LOGB0_IS_MIN and __FP_LOGBNAN_IS_MIN.
146
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)'.
151
152 */
153
154 #include <bits/fp-logb.h>
155 #ifdef __USE_ISOC99
156 # if __FP_LOGB0_IS_MIN
157 # define FP_ILOGB0 (-2147483647 - 1)
158 # else
159 # define FP_ILOGB0 (-2147483647)
160 # endif
161 # if __FP_LOGBNAN_IS_MIN
162 # define FP_ILOGBNAN (-2147483647 - 1)
163 # else
164 # define FP_ILOGBNAN 2147483647
165 # endif
166 #endif
167 #if __GLIBC_USE (IEC_60559_BFP_EXT)
168 # if __WORDSIZE == 32
169 # define __FP_LONG_MAX 0x7fffffffL
170 # else
171 # define __FP_LONG_MAX 0x7fffffffffffffffL
172 # endif
173 # if __FP_LOGB0_IS_MIN
174 # define FP_LLOGB0 (-__FP_LONG_MAX - 1)
175 # else
176 # define FP_LLOGB0 (-__FP_LONG_MAX)
177 # endif
178 # if __FP_LOGBNAN_IS_MIN
179 # define FP_LLOGBNAN (-__FP_LONG_MAX - 1)
180 # else
181 # define FP_LLOGBNAN __FP_LONG_MAX
182 # endif
183 #endif
184
185 /* Get the architecture specific values describing the floating-point
186 evaluation. The following symbols will get defined:
187
188 FP_FAST_FMA
189 FP_FAST_FMAF
190 FP_FAST_FMAL
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.
195 */
196
197 #include <bits/fp-fast.h>
198
199 #if __GLIBC_USE (IEC_60559_BFP_EXT)
200 /* Rounding direction macros for fromfp functions. */
201 enum
202 {
203 FP_INT_UPWARD =
204 # define FP_INT_UPWARD 0
205 FP_INT_UPWARD,
206 FP_INT_DOWNWARD =
207 # define FP_INT_DOWNWARD 1
208 FP_INT_DOWNWARD,
209 FP_INT_TOWARDZERO =
210 # define FP_INT_TOWARDZERO 2
211 FP_INT_TOWARDZERO,
212 FP_INT_TONEARESTFROMZERO =
213 # define FP_INT_TONEARESTFROMZERO 3
214 FP_INT_TONEARESTFROMZERO,
215 FP_INT_TONEAREST =
216 # define FP_INT_TONEAREST 4
217 FP_INT_TONEAREST,
218 };
219 #endif
220
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'. */
225
226 #define __SIMD_DECL(function) __CONCAT (__DECL_SIMD_, function)
227
228 #define __MATHCALL_VEC(function, suffix, args) \
229 __SIMD_DECL (__MATH_PRECNAME (function, suffix)) \
230 __MATHCALL (function, suffix, args)
231
232 #define __MATHDECL_VEC(type, function,suffix, args) \
233 __SIMD_DECL (__MATH_PRECNAME (function, suffix)) \
234 __MATHDECL(type, function,suffix, args)
235
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
248
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>
255 #undef _Mdouble_
256 #undef __MATH_PRECNAME
257 #undef __MATH_DECLARING_DOUBLE
258 #undef __MATH_DECLARING_FLOATN
259
260 #ifdef __USE_ISOC99
261
262
263 /* Include the file of declarations again, this time using `float'
264 instead of `double' and appending f to each function name. */
265
266 # ifndef _Mfloat_
267 # define _Mfloat_ float
268 # endif
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>
275 # undef _Mdouble_
276 # undef __MATH_PRECNAME
277 # undef __MATH_DECLARING_DOUBLE
278 # undef __MATH_DECLARING_FLOATN
279
280 # if !(defined __NO_LONG_DOUBLE_MATH && defined _LIBC) \
281 || defined __LDBL_COMPAT \
282 || defined _LIBC_TEST
283 # ifdef __LDBL_COMPAT
284
285 # ifdef __USE_ISOC99
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),
290 __nldbl_nexttowardf)
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__));
297 # endif
298 # endif
299
300 # undef __MATHDECL_1
301 # define __MATHDECL_2(type, function,suffix, args, alias) \
302 extern type __REDIRECT_NTH(__MATH_PRECNAME(function,suffix), \
303 args, alias)
304 # define __MATHDECL_1(type, function,suffix, args) \
305 __MATHDECL_2(type, function,suffix, args, __CONCAT(function,suffix))
306 # endif
307
308 /* Include the file of declarations again, this time using `long double'
309 instead of `double' and appending l to each function name. */
310
311 # ifndef _Mlong_double_
312 # define _Mlong_double_ long double
313 # endif
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>
321 # undef _Mdouble_
322 # undef __MATH_PRECNAME
323 # undef __MATH_DECLARING_DOUBLE
324 # undef __MATH_DECLARING_FLOATN
325
326 # endif /* !(__NO_LONG_DOUBLE_MATH && _LIBC) || __LDBL_COMPAT */
327
328 #endif /* Use ISO C99. */
329
330 /* Include the file of declarations again, this time using `_Float128'
331 instead of `double' and appending f128 to each function name. */
332
333 #if __HAVE_DISTINCT_FLOAT128 || (__HAVE_FLOAT128 && !defined _LIBC)
334 # ifndef _Mfloat128_
335 # define _Mfloat128_ _Float128
336 # endif
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>
343 # endif
344 # if __GLIBC_USE (IEC_60559_TYPES_EXT)
345 # include <bits/mathcalls.h>
346 # endif
347 # undef _Mdouble_
348 # undef __MATH_PRECNAME
349 # undef __MATH_DECLARING_DOUBLE
350 # undef __MATH_DECLARING_FLOATN
351 #endif /* __HAVE_DISTINCT_FLOAT128. */
352
353 #undef __MATHDECL_1
354 #undef __MATHDECL
355 #undef __MATHCALL
356
357
358 #if defined __USE_MISC || defined __USE_XOPEN
359 /* This variable is used by `gamma' and `lgamma'. */
360 extern int signgam;
361 #endif
362
363
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)
384 # else
385 # define __MATH_TG(TG_ARG, FUNC, ARGS) \
386 __builtin_choose_expr \
387 (__builtin_types_compatible_p (__typeof (TG_ARG), float), \
388 FUNC ## f ARGS, \
389 __builtin_choose_expr \
390 (__builtin_types_compatible_p (__typeof (TG_ARG), double), \
391 FUNC ARGS, \
392 __builtin_choose_expr \
393 (__builtin_types_compatible_p (__typeof (TG_ARG), long double), \
394 FUNC ## l ARGS, \
395 FUNC ## f128 ARGS)))
396 # endif
397 #else
398 # define __MATH_TG(TG_ARG, FUNC, ARGS) \
399 (sizeof (TG_ARG) == sizeof (float) \
400 ? FUNC ## f ARGS \
401 : sizeof (TG_ARG) == sizeof (double) \
402 ? FUNC ARGS \
403 : FUNC ## l ARGS)
404 #endif
405
406 /* ISO C99 defines some generic macros which work on any data type. */
407 #ifdef __USE_ISOC99
408
409 /* All floating-point numbers can be put in one of these categories. */
410 enum
411 {
412 FP_NAN =
413 # define FP_NAN 0
414 FP_NAN,
415 FP_INFINITE =
416 # define FP_INFINITE 1
417 FP_INFINITE,
418 FP_ZERO =
419 # define FP_ZERO 2
420 FP_ZERO,
421 FP_SUBNORMAL =
422 # define FP_SUBNORMAL 3
423 FP_SUBNORMAL,
424 FP_NORMAL =
425 # define FP_NORMAL 4
426 FP_NORMAL
427 };
428
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. */
432
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)
444 # else
445 # define fpclassify(x) __MATH_TG ((x), __fpclassify, (x))
446 # endif
447
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 __GNUC_PREREQ (4,0)
452 # define signbit(x) __MATH_TG ((x), __builtin_signbit, (x))
453 # else
454 # define signbit(x) __MATH_TG ((x), __signbit, (x))
455 # endif
456
457 /* Return nonzero value if X is not +-Inf or NaN. */
458 # if __GNUC_PREREQ (4,4) && !defined __SUPPORT_SNAN__
459 # define isfinite(x) __builtin_isfinite (x)
460 # else
461 # define isfinite(x) __MATH_TG ((x), __finite, (x))
462 # endif
463
464 /* Return nonzero value if X is neither zero, subnormal, Inf, nor NaN. */
465 # if __GNUC_PREREQ (4,4) && !defined __SUPPORT_SNAN__
466 # define isnormal(x) __builtin_isnormal (x)
467 # else
468 # define isnormal(x) (fpclassify (x) == FP_NORMAL)
469 # endif
470
471 /* Return nonzero value if X is a NaN. We could use `fpclassify' but
472 we already have this functions `__isnan' and it is faster. */
473 # if __GNUC_PREREQ (4,4) && !defined __SUPPORT_SNAN__
474 # define isnan(x) __builtin_isnan (x)
475 # else
476 # define isnan(x) __MATH_TG ((x), __isnan, (x))
477 # endif
478
479 /* Return nonzero value if X is positive or negative infinity. */
480 # if __HAVE_DISTINCT_FLOAT128 && !__GNUC_PREREQ (7,0) \
481 && !defined __SUPPORT_SNAN__ && !defined __cplusplus
482 /* Since __builtin_isinf_sign is broken for float128 before GCC 7.0,
483 use the helper function, __isinff128, with older compilers. This is
484 only provided for C mode, because in C++ mode, GCC has no support
485 for __builtin_types_compatible_p (and when in C++ mode, this macro is
486 not used anyway, because libstdc++ headers undefine it). */
487 # define isinf(x) \
488 (__builtin_types_compatible_p (__typeof (x), _Float128) \
489 ? __isinff128 (x) : __builtin_isinf_sign (x))
490 # elif __GNUC_PREREQ (4,4) && !defined __SUPPORT_SNAN__
491 # define isinf(x) __builtin_isinf_sign (x)
492 # else
493 # define isinf(x) __MATH_TG ((x), __isinf, (x))
494 # endif
495
496 /* Bitmasks for the math_errhandling macro. */
497 # define MATH_ERRNO 1 /* errno set by math functions. */
498 # define MATH_ERREXCEPT 2 /* Exceptions raised by math functions. */
499
500 /* By default all functions support both errno and exception handling.
501 In gcc's fast math mode and if inline functions are defined this
502 might not be true. */
503 # ifndef __FAST_MATH__
504 # define math_errhandling (MATH_ERRNO | MATH_ERREXCEPT)
505 # endif
506
507 #endif /* Use ISO C99. */
508
509 #if __GLIBC_USE (IEC_60559_BFP_EXT)
510 # include <bits/iscanonical.h>
511
512 /* Return nonzero value if X is a signaling NaN. */
513 # ifndef __cplusplus
514 # define issignaling(x) __MATH_TG ((x), __issignaling, (x))
515 # else
516 /* In C++ mode, __MATH_TG cannot be used, because it relies on
517 __builtin_types_compatible_p, which is a C-only builtin. On the
518 other hand, overloading provides the means to distinguish between
519 the floating-point types. The overloading resolution will match
520 the correct parameter (regardless of type qualifiers (i.e.: const
521 and volatile). */
522 extern "C++" {
523 inline int issignaling (float __val) { return __issignalingf (__val); }
524 inline int issignaling (double __val) { return __issignaling (__val); }
525 inline int
526 issignaling (long double __val)
527 {
528 # ifdef __NO_LONG_DOUBLE_MATH
529 return __issignaling (__val);
530 # else
531 return __issignalingl (__val);
532 # endif
533 }
534 # if __HAVE_DISTINCT_FLOAT128
535 inline int issignaling (_Float128 __val) { return __issignalingf128 (__val); }
536 # endif
537 } /* extern C++ */
538 # endif
539
540 /* Return nonzero value if X is subnormal. */
541 # define issubnormal(x) (fpclassify (x) == FP_SUBNORMAL)
542
543 /* Return nonzero value if X is zero. */
544 # ifndef __cplusplus
545 # ifdef __SUPPORT_SNAN__
546 # define iszero(x) (fpclassify (x) == FP_ZERO)
547 # else
548 # define iszero(x) (((__typeof (x)) (x)) == 0)
549 # endif
550 # else /* __cplusplus */
551 extern "C++" {
552 # ifdef __SUPPORT_SNAN__
553 inline int
554 iszero (float __val)
555 {
556 return __fpclassifyf (__val) == FP_ZERO;
557 }
558 inline int
559 iszero (double __val)
560 {
561 return __fpclassify (__val) == FP_ZERO;
562 }
563 inline int
564 iszero (long double __val)
565 {
566 # ifdef __NO_LONG_DOUBLE_MATH
567 return __fpclassify (__val) == FP_ZERO;
568 # else
569 return __fpclassifyl (__val) == FP_ZERO;
570 # endif
571 }
572 # if __HAVE_DISTINCT_FLOAT128
573 inline int
574 iszero (_Float128 __val)
575 {
576 return __fpclassifyf128 (__val) == FP_ZERO;
577 }
578 # endif
579 # else
580 template <class __T> inline bool
581 iszero (__T __val)
582 {
583 return __val == 0;
584 }
585 # endif
586 } /* extern C++ */
587 # endif /* __cplusplus */
588 #endif /* Use IEC_60559_BFP_EXT. */
589
590 #ifdef __USE_XOPEN
591 /* X/Open wants another strange constant. */
592 # define MAXFLOAT 3.40282347e+38F
593 #endif
594
595
596 /* Some useful constants. */
597 #if defined __USE_MISC || defined __USE_XOPEN
598 # define M_E 2.7182818284590452354 /* e */
599 # define M_LOG2E 1.4426950408889634074 /* log_2 e */
600 # define M_LOG10E 0.43429448190325182765 /* log_10 e */
601 # define M_LN2 0.69314718055994530942 /* log_e 2 */
602 # define M_LN10 2.30258509299404568402 /* log_e 10 */
603 # define M_PI 3.14159265358979323846 /* pi */
604 # define M_PI_2 1.57079632679489661923 /* pi/2 */
605 # define M_PI_4 0.78539816339744830962 /* pi/4 */
606 # define M_1_PI 0.31830988618379067154 /* 1/pi */
607 # define M_2_PI 0.63661977236758134308 /* 2/pi */
608 # define M_2_SQRTPI 1.12837916709551257390 /* 2/sqrt(pi) */
609 # define M_SQRT2 1.41421356237309504880 /* sqrt(2) */
610 # define M_SQRT1_2 0.70710678118654752440 /* 1/sqrt(2) */
611 #endif
612
613 /* The above constants are not adequate for computation using `long double's.
614 Therefore we provide as an extension constants with similar names as a
615 GNU extension. Provide enough digits for the 128-bit IEEE quad. */
616 #ifdef __USE_GNU
617 # define M_El 2.718281828459045235360287471352662498L /* e */
618 # define M_LOG2El 1.442695040888963407359924681001892137L /* log_2 e */
619 # define M_LOG10El 0.434294481903251827651128918916605082L /* log_10 e */
620 # define M_LN2l 0.693147180559945309417232121458176568L /* log_e 2 */
621 # define M_LN10l 2.302585092994045684017991454684364208L /* log_e 10 */
622 # define M_PIl 3.141592653589793238462643383279502884L /* pi */
623 # define M_PI_2l 1.570796326794896619231321691639751442L /* pi/2 */
624 # define M_PI_4l 0.785398163397448309615660845819875721L /* pi/4 */
625 # define M_1_PIl 0.318309886183790671537767526745028724L /* 1/pi */
626 # define M_2_PIl 0.636619772367581343075535053490057448L /* 2/pi */
627 # define M_2_SQRTPIl 1.128379167095512573896158903121545172L /* 2/sqrt(pi) */
628 # define M_SQRT2l 1.414213562373095048801688724209698079L /* sqrt(2) */
629 # define M_SQRT1_2l 0.707106781186547524400844362104849039L /* 1/sqrt(2) */
630 #endif
631
632 #if __HAVE_FLOAT128 && defined __USE_GNU
633 # define M_Ef128 __f128 (2.718281828459045235360287471352662498) /* e */
634 # define M_LOG2Ef128 __f128 (1.442695040888963407359924681001892137) /* log_2 e */
635 # define M_LOG10Ef128 __f128 (0.434294481903251827651128918916605082) /* log_10 e */
636 # define M_LN2f128 __f128 (0.693147180559945309417232121458176568) /* log_e 2 */
637 # define M_LN10f128 __f128 (2.302585092994045684017991454684364208) /* log_e 10 */
638 # define M_PIf128 __f128 (3.141592653589793238462643383279502884) /* pi */
639 # define M_PI_2f128 __f128 (1.570796326794896619231321691639751442) /* pi/2 */
640 # define M_PI_4f128 __f128 (0.785398163397448309615660845819875721) /* pi/4 */
641 # define M_1_PIf128 __f128 (0.318309886183790671537767526745028724) /* 1/pi */
642 # define M_2_PIf128 __f128 (0.636619772367581343075535053490057448) /* 2/pi */
643 # define M_2_SQRTPIf128 __f128 (1.128379167095512573896158903121545172) /* 2/sqrt(pi) */
644 # define M_SQRT2f128 __f128 (1.414213562373095048801688724209698079) /* sqrt(2) */
645 # define M_SQRT1_2f128 __f128 (0.707106781186547524400844362104849039) /* 1/sqrt(2) */
646 #endif
647
648 /* When compiling in strict ISO C compatible mode we must not use the
649 inline functions since they, among other things, do not set the
650 `errno' variable correctly. */
651 #if defined __STRICT_ANSI__ && !defined __NO_MATH_INLINES
652 # define __NO_MATH_INLINES 1
653 #endif
654
655 #ifdef __USE_ISOC99
656 # if __GNUC_PREREQ (3, 1)
657 /* ISO C99 defines some macros to compare number while taking care for
658 unordered numbers. Many FPUs provide special instructions to support
659 these operations. Generic support in GCC for these as builtins went
660 in 2.97, but not all cpus added their patterns until 3.1. Therefore
661 we enable the builtins from 3.1 onwards and use a generic implementation
662 othwerwise. */
663 # define isgreater(x, y) __builtin_isgreater(x, y)
664 # define isgreaterequal(x, y) __builtin_isgreaterequal(x, y)
665 # define isless(x, y) __builtin_isless(x, y)
666 # define islessequal(x, y) __builtin_islessequal(x, y)
667 # define islessgreater(x, y) __builtin_islessgreater(x, y)
668 # define isunordered(x, y) __builtin_isunordered(x, y)
669 # else
670 # define isgreater(x, y) \
671 (__extension__ ({ __typeof__ (x) __x = (x); __typeof__ (y) __y = (y); \
672 !isunordered (__x, __y) && __x > __y; }))
673 # define isgreaterequal(x, y) \
674 (__extension__ ({ __typeof__ (x) __x = (x); __typeof__ (y) __y = (y); \
675 !isunordered (__x, __y) && __x >= __y; }))
676 # define isless(x, y) \
677 (__extension__ ({ __typeof__ (x) __x = (x); __typeof__ (y) __y = (y); \
678 !isunordered (__x, __y) && __x < __y; }))
679 # define islessequal(x, y) \
680 (__extension__ ({ __typeof__ (x) __x = (x); __typeof__ (y) __y = (y); \
681 !isunordered (__x, __y) && __x <= __y; }))
682 # define islessgreater(x, y) \
683 (__extension__ ({ __typeof__ (x) __x = (x); __typeof__ (y) __y = (y); \
684 !isunordered (__x, __y) && __x != __y; }))
685 /* isunordered must always check both operands first for signaling NaNs. */
686 # define isunordered(x, y) \
687 (__extension__ ({ __typeof__ (x) __u = (x); __typeof__ (y) __v = (y); \
688 __u != __v && (__u != __u || __v != __v); }))
689 # endif
690 #endif
691
692 /* Get machine-dependent inline versions (if there are any). */
693 #ifdef __USE_EXTERN_INLINES
694 # include <bits/mathinline.h>
695 #endif
696
697 /* Define special entry points to use when the compiler got told to
698 only expect finite results. */
699 #if defined __FINITE_MATH_ONLY__ && __FINITE_MATH_ONLY__ > 0
700
701 /* Include bits/math-finite.h for double. */
702 # define _Mdouble_ double
703 # define __MATH_DECLARING_DOUBLE 1
704 # define __MATH_DECLARING_FLOATN 0
705 # define __REDIRFROM_X(function, reentrant) \
706 function ## reentrant
707 # define __REDIRTO_X(function, reentrant) \
708 __ ## function ## reentrant ## _finite
709 # include <bits/math-finite.h>
710 # undef _Mdouble_
711 # undef __MATH_DECLARING_DOUBLE
712 # undef __MATH_DECLARING_FLOATN
713 # undef __REDIRFROM_X
714 # undef __REDIRTO_X
715
716 /* When __USE_ISOC99 is defined, include math-finite for float and
717 long double, as well. */
718 # ifdef __USE_ISOC99
719
720 /* Include bits/math-finite.h for float. */
721 # define _Mdouble_ float
722 # define __MATH_DECLARING_DOUBLE 0
723 # define __MATH_DECLARING_FLOATN 0
724 # define __REDIRFROM_X(function, reentrant) \
725 function ## f ## reentrant
726 # define __REDIRTO_X(function, reentrant) \
727 __ ## function ## f ## reentrant ## _finite
728 # include <bits/math-finite.h>
729 # undef _Mdouble_
730 # undef __MATH_DECLARING_DOUBLE
731 # undef __MATH_DECLARING_FLOATN
732 # undef __REDIRFROM_X
733 # undef __REDIRTO_X
734
735 /* Include bits/math-finite.h for long double. */
736 # ifdef __MATH_DECLARE_LDOUBLE
737 # define _Mdouble_ long double
738 # define __MATH_DECLARING_DOUBLE 0
739 # define __MATH_DECLARING_FLOATN 0
740 # define __REDIRFROM_X(function, reentrant) \
741 function ## l ## reentrant
742 # ifdef __NO_LONG_DOUBLE_MATH
743 # define __REDIRTO_X(function, reentrant) \
744 __ ## function ## reentrant ## _finite
745 # else
746 # define __REDIRTO_X(function, reentrant) \
747 __ ## function ## l ## reentrant ## _finite
748 # endif
749 # include <bits/math-finite.h>
750 # undef _Mdouble_
751 # undef __MATH_DECLARING_DOUBLE
752 # undef __MATH_DECLARING_FLOATN
753 # undef __REDIRFROM_X
754 # undef __REDIRTO_X
755 # endif
756
757 # endif /* __USE_ISOC99. */
758
759 /* Include bits/math-finite.h for float128. */
760 # if (__HAVE_DISTINCT_FLOAT128 || (__HAVE_FLOAT128 && !defined _LIBC)) \
761 && __GLIBC_USE (IEC_60559_TYPES_EXT)
762 # define _Mdouble_ _Float128
763 # define __MATH_DECLARING_DOUBLE 0
764 # define __MATH_DECLARING_FLOATN 1
765 # define __REDIRFROM_X(function, reentrant) \
766 function ## f128 ## reentrant
767 # if __HAVE_DISTINCT_FLOAT128
768 # define __REDIRTO_X(function, reentrant) \
769 __ ## function ## f128 ## reentrant ## _finite
770 # else
771 # define __REDIRTO_X(function, reentrant) \
772 __ ## function ## l ## reentrant ## _finite
773 # endif
774 # include <bits/math-finite.h>
775 # undef _Mdouble_
776 # undef __MATH_DECLARING_DOUBLE
777 # undef __MATH_DECLARING_FLOATN
778 # undef __REDIRFROM_X
779 # undef __REDIRTO_X
780 # endif
781 #endif /* __FINITE_MATH_ONLY__ > 0. */
782
783 #if __GLIBC_USE (IEC_60559_BFP_EXT)
784 /* An expression whose type has the widest of the evaluation formats
785 of X and Y (which are of floating-point types). */
786 # if __FLT_EVAL_METHOD__ == 2 || __FLT_EVAL_METHOD__ > 64
787 # define __MATH_EVAL_FMT2(x, y) ((x) + (y) + 0.0L)
788 # elif __FLT_EVAL_METHOD__ == 1 || __FLT_EVAL_METHOD__ > 32
789 # define __MATH_EVAL_FMT2(x, y) ((x) + (y) + 0.0)
790 # else
791 # define __MATH_EVAL_FMT2(x, y) ((x) + (y))
792 # endif
793
794 /* Return X == Y but raising "invalid" and setting errno if X or Y is
795 a NaN. */
796 # define iseqsig(x, y) \
797 __MATH_TG (__MATH_EVAL_FMT2 (x, y), __iseqsig, ((x), (y)))
798 #endif
799
800 __END_DECLS
801
802
803 #endif /* math.h */