]> git.ipfire.org Git - thirdparty/glibc.git/blob - math/math.h
math/math.h (HUGE_VAL): Improve commentary.
[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 __BEGIN_DECLS
30
31 /* Get definitions of __intmax_t and __uintmax_t. */
32 #include <bits/types.h>
33
34 /* Get machine-dependent vector math functions declarations. */
35 #include <bits/math-vector.h>
36
37 /* Gather machine dependent type support. */
38 #include <bits/floatn.h>
39
40 /* Value returned on overflow. With IEEE 754 floating point, this is
41 +Infinity, otherwise the largest representable positive value. */
42 #if __GNUC_PREREQ (3, 3)
43 # define HUGE_VAL (__builtin_huge_val ())
44 #else
45 /* This may provoke compiler warnings, and may not be rounded to
46 +Infinity in all IEEE 754 rounding modes, but is the best that can
47 be done in ISO C while remaining a constant expression. 10,000 is
48 greater than the maximum (decimal) exponent for all supported
49 floating-point formats and widths. */
50 # define HUGE_VAL 1e10000
51 #endif
52 #ifdef __USE_ISOC99
53 # if __GNUC_PREREQ (3, 3)
54 # define HUGE_VALF (__builtin_huge_valf ())
55 # define HUGE_VALL (__builtin_huge_vall ())
56 # else
57 # define HUGE_VALF 1e10000f
58 # define HUGE_VALL 1e10000L
59 # endif
60 #endif
61 #if __HAVE_FLOAT128 && __GLIBC_USE (IEC_60559_TYPES_EXT)
62 # define HUGE_VAL_F128 (__builtin_huge_valf128 ())
63 #endif
64
65 #ifdef __USE_ISOC99
66 /* IEEE positive infinity. */
67 # if __GNUC_PREREQ (3, 3)
68 # define INFINITY (__builtin_inff ())
69 # else
70 # define INFINITY HUGE_VALF
71 # endif
72
73 /* IEEE Not A Number. */
74 # if __GNUC_PREREQ (3, 3)
75 # define NAN (__builtin_nanf (""))
76 # else
77 /* This will raise an "invalid" exception outside static initializers,
78 but is the best that can be done in ISO C while remaining a
79 constant expression. */
80 # define NAN (0.0f / 0.0f)
81 # endif
82 #endif /* __USE_ISOC99 */
83
84 #if __GLIBC_USE (IEC_60559_BFP_EXT)
85 /* Signaling NaN macros, if supported. */
86 # if __GNUC_PREREQ (3, 3)
87 # define SNANF (__builtin_nansf (""))
88 # define SNAN (__builtin_nans (""))
89 # define SNANL (__builtin_nansl (""))
90 # endif
91 #endif
92 #if __HAVE_FLOAT128 && __GLIBC_USE (IEC_60559_TYPES_EXT)
93 # define SNANF128 (__builtin_nansf128 (""))
94 #endif
95
96 /* Get __GLIBC_FLT_EVAL_METHOD. */
97 #include <bits/flt-eval-method.h>
98
99 #ifdef __USE_ISOC99
100 /* Define the following typedefs.
101
102 float_t floating-point type at least as wide as `float' used
103 to evaluate `float' expressions
104 double_t floating-point type at least as wide as `double' used
105 to evaluate `double' expressions
106 */
107 # if __GLIBC_FLT_EVAL_METHOD == 0 || __GLIBC_FLT_EVAL_METHOD == 16
108 typedef float float_t;
109 typedef double double_t;
110 # elif __GLIBC_FLT_EVAL_METHOD == 1
111 typedef double float_t;
112 typedef double double_t;
113 # elif __GLIBC_FLT_EVAL_METHOD == 2
114 typedef long double float_t;
115 typedef long double double_t;
116 # elif __GLIBC_FLT_EVAL_METHOD == 32
117 typedef _Float32 float_t;
118 typedef double double_t;
119 # elif __GLIBC_FLT_EVAL_METHOD == 33
120 typedef _Float32x float_t;
121 typedef _Float32x double_t;
122 # elif __GLIBC_FLT_EVAL_METHOD == 64
123 typedef _Float64 float_t;
124 typedef _Float64 double_t;
125 # elif __GLIBC_FLT_EVAL_METHOD == 65
126 typedef _Float64x float_t;
127 typedef _Float64x double_t;
128 # elif __GLIBC_FLT_EVAL_METHOD == 128
129 typedef _Float128 float_t;
130 typedef _Float128 double_t;
131 # elif __GLIBC_FLT_EVAL_METHOD == 129
132 typedef _Float128x float_t;
133 typedef _Float128x double_t;
134 # else
135 # error "Unknown __GLIBC_FLT_EVAL_METHOD"
136 # endif
137 #endif
138
139 /* Define macros for the return values of ilogb and llogb, based on
140 __FP_LOGB0_IS_MIN and __FP_LOGBNAN_IS_MIN.
141
142 FP_ILOGB0 Expands to a value returned by `ilogb (0.0)'.
143 FP_ILOGBNAN Expands to a value returned by `ilogb (NAN)'.
144 FP_LLOGB0 Expands to a value returned by `llogb (0.0)'.
145 FP_LLOGBNAN Expands to a value returned by `llogb (NAN)'.
146
147 */
148
149 #include <bits/fp-logb.h>
150 #ifdef __USE_ISOC99
151 # if __FP_LOGB0_IS_MIN
152 # define FP_ILOGB0 (-2147483647 - 1)
153 # else
154 # define FP_ILOGB0 (-2147483647)
155 # endif
156 # if __FP_LOGBNAN_IS_MIN
157 # define FP_ILOGBNAN (-2147483647 - 1)
158 # else
159 # define FP_ILOGBNAN 2147483647
160 # endif
161 #endif
162 #if __GLIBC_USE (IEC_60559_BFP_EXT)
163 # if __WORDSIZE == 32
164 # define __FP_LONG_MAX 0x7fffffffL
165 # else
166 # define __FP_LONG_MAX 0x7fffffffffffffffL
167 # endif
168 # if __FP_LOGB0_IS_MIN
169 # define FP_LLOGB0 (-__FP_LONG_MAX - 1)
170 # else
171 # define FP_LLOGB0 (-__FP_LONG_MAX)
172 # endif
173 # if __FP_LOGBNAN_IS_MIN
174 # define FP_LLOGBNAN (-__FP_LONG_MAX - 1)
175 # else
176 # define FP_LLOGBNAN __FP_LONG_MAX
177 # endif
178 #endif
179
180 /* Get the architecture specific values describing the floating-point
181 evaluation. The following symbols will get defined:
182
183 FP_FAST_FMA
184 FP_FAST_FMAF
185 FP_FAST_FMAL
186 If defined it indicates that the `fma' function
187 generally executes about as fast as a multiply and an add.
188 This macro is defined only iff the `fma' function is
189 implemented directly with a hardware multiply-add instructions.
190 */
191
192 #include <bits/fp-fast.h>
193
194 #if __GLIBC_USE (IEC_60559_BFP_EXT)
195 /* Rounding direction macros for fromfp functions. */
196 enum
197 {
198 FP_INT_UPWARD =
199 # define FP_INT_UPWARD 0
200 FP_INT_UPWARD,
201 FP_INT_DOWNWARD =
202 # define FP_INT_DOWNWARD 1
203 FP_INT_DOWNWARD,
204 FP_INT_TOWARDZERO =
205 # define FP_INT_TOWARDZERO 2
206 FP_INT_TOWARDZERO,
207 FP_INT_TONEARESTFROMZERO =
208 # define FP_INT_TONEARESTFROMZERO 3
209 FP_INT_TONEARESTFROMZERO,
210 FP_INT_TONEAREST =
211 # define FP_INT_TONEAREST 4
212 FP_INT_TONEAREST,
213 };
214 #endif
215
216 /* The file <bits/mathcalls.h> contains the prototypes for all the
217 actual math functions. These macros are used for those prototypes,
218 so we can easily declare each function as both `name' and `__name',
219 and can declare the float versions `namef' and `__namef'. */
220
221 #define __SIMD_DECL(function) __CONCAT (__DECL_SIMD_, function)
222
223 #define __MATHCALL_VEC(function, suffix, args) \
224 __SIMD_DECL (__MATH_PRECNAME (function, suffix)) \
225 __MATHCALL (function, suffix, args)
226
227 #define __MATHDECL_VEC(type, function,suffix, args) \
228 __SIMD_DECL (__MATH_PRECNAME (function, suffix)) \
229 __MATHDECL(type, function,suffix, args)
230
231 #define __MATHCALL(function,suffix, args) \
232 __MATHDECL (_Mdouble_,function,suffix, args)
233 #define __MATHDECL(type, function,suffix, args) \
234 __MATHDECL_1(type, function,suffix, args); \
235 __MATHDECL_1(type, __CONCAT(__,function),suffix, args)
236 #define __MATHCALLX(function,suffix, args, attrib) \
237 __MATHDECLX (_Mdouble_,function,suffix, args, attrib)
238 #define __MATHDECLX(type, function,suffix, args, attrib) \
239 __MATHDECL_1(type, function,suffix, args) __attribute__ (attrib); \
240 __MATHDECL_1(type, __CONCAT(__,function),suffix, args) __attribute__ (attrib)
241 #define __MATHDECL_1(type, function,suffix, args) \
242 extern type __MATH_PRECNAME(function,suffix) args __THROW
243
244 #define _Mdouble_ double
245 #define __MATH_PRECNAME(name,r) __CONCAT(name,r)
246 #define __MATH_DECLARING_DOUBLE 1
247 #define __MATH_DECLARING_FLOATN 0
248 #include <bits/mathcalls-helper-functions.h>
249 #include <bits/mathcalls.h>
250 #undef _Mdouble_
251 #undef __MATH_PRECNAME
252 #undef __MATH_DECLARING_DOUBLE
253 #undef __MATH_DECLARING_FLOATN
254
255 #ifdef __USE_ISOC99
256
257
258 /* Include the file of declarations again, this time using `float'
259 instead of `double' and appending f to each function name. */
260
261 # ifndef _Mfloat_
262 # define _Mfloat_ float
263 # endif
264 # define _Mdouble_ _Mfloat_
265 # define __MATH_PRECNAME(name,r) name##f##r
266 # define __MATH_DECLARING_DOUBLE 0
267 # define __MATH_DECLARING_FLOATN 0
268 # include <bits/mathcalls-helper-functions.h>
269 # include <bits/mathcalls.h>
270 # undef _Mdouble_
271 # undef __MATH_PRECNAME
272 # undef __MATH_DECLARING_DOUBLE
273 # undef __MATH_DECLARING_FLOATN
274
275 # if !(defined __NO_LONG_DOUBLE_MATH && defined _LIBC) \
276 || defined __LDBL_COMPAT \
277 || defined _LIBC_TEST
278 # ifdef __LDBL_COMPAT
279
280 # ifdef __USE_ISOC99
281 extern float __nldbl_nexttowardf (float __x, long double __y)
282 __THROW __attribute__ ((__const__));
283 # ifdef __REDIRECT_NTH
284 extern float __REDIRECT_NTH (nexttowardf, (float __x, long double __y),
285 __nldbl_nexttowardf)
286 __attribute__ ((__const__));
287 extern double __REDIRECT_NTH (nexttoward, (double __x, long double __y),
288 nextafter) __attribute__ ((__const__));
289 extern long double __REDIRECT_NTH (nexttowardl,
290 (long double __x, long double __y),
291 nextafter) __attribute__ ((__const__));
292 # endif
293 # endif
294
295 # undef __MATHDECL_1
296 # define __MATHDECL_2(type, function,suffix, args, alias) \
297 extern type __REDIRECT_NTH(__MATH_PRECNAME(function,suffix), \
298 args, alias)
299 # define __MATHDECL_1(type, function,suffix, args) \
300 __MATHDECL_2(type, function,suffix, args, __CONCAT(function,suffix))
301 # endif
302
303 /* Include the file of declarations again, this time using `long double'
304 instead of `double' and appending l to each function name. */
305
306 # ifndef _Mlong_double_
307 # define _Mlong_double_ long double
308 # endif
309 # define _Mdouble_ _Mlong_double_
310 # define __MATH_PRECNAME(name,r) name##l##r
311 # define __MATH_DECLARING_DOUBLE 0
312 # define __MATH_DECLARING_FLOATN 0
313 # define __MATH_DECLARE_LDOUBLE 1
314 # include <bits/mathcalls-helper-functions.h>
315 # include <bits/mathcalls.h>
316 # undef _Mdouble_
317 # undef __MATH_PRECNAME
318 # undef __MATH_DECLARING_DOUBLE
319 # undef __MATH_DECLARING_FLOATN
320
321 # endif /* !(__NO_LONG_DOUBLE_MATH && _LIBC) || __LDBL_COMPAT */
322
323 #endif /* Use ISO C99. */
324
325 /* Include the file of declarations again, this time using `_Float128'
326 instead of `double' and appending f128 to each function name. */
327
328 #if __HAVE_DISTINCT_FLOAT128 || (__HAVE_FLOAT128 && !defined _LIBC)
329 # ifndef _Mfloat128_
330 # define _Mfloat128_ _Float128
331 # endif
332 # define _Mdouble_ _Mfloat128_
333 # define __MATH_PRECNAME(name,r) name##f128##r
334 # define __MATH_DECLARING_DOUBLE 0
335 # define __MATH_DECLARING_FLOATN 1
336 # if __HAVE_DISTINCT_FLOAT128
337 # include <bits/mathcalls-helper-functions.h>
338 # endif
339 # if __GLIBC_USE (IEC_60559_TYPES_EXT)
340 # include <bits/mathcalls.h>
341 # endif
342 # undef _Mdouble_
343 # undef __MATH_PRECNAME
344 # undef __MATH_DECLARING_DOUBLE
345 # undef __MATH_DECLARING_FLOATN
346 #endif /* __HAVE_DISTINCT_FLOAT128. */
347
348 #undef __MATHDECL_1
349 #undef __MATHDECL
350 #undef __MATHCALL
351
352
353 #if defined __USE_MISC || defined __USE_XOPEN
354 /* This variable is used by `gamma' and `lgamma'. */
355 extern int signgam;
356 #endif
357
358
359 /* Depending on the type of TG_ARG, call an appropriately suffixed
360 version of FUNC with arguments (including parentheses) ARGS.
361 Suffixed functions may not exist for long double if it has the same
362 format as double, or for other types with the same format as float,
363 double or long double. The behavior is undefined if the argument
364 does not have a real floating type. The definition may use a
365 conditional expression, so all suffixed versions of FUNC must
366 return the same type (FUNC may include a cast if necessary rather
367 than being a single identifier). */
368 #ifdef __NO_LONG_DOUBLE_MATH
369 # define __MATH_TG(TG_ARG, FUNC, ARGS) \
370 (sizeof (TG_ARG) == sizeof (float) ? FUNC ## f ARGS : FUNC ARGS)
371 #elif __HAVE_DISTINCT_FLOAT128
372 # if __HAVE_GENERIC_SELECTION
373 # define __MATH_TG(TG_ARG, FUNC, ARGS) \
374 _Generic ((TG_ARG), \
375 float: FUNC ## f ARGS, \
376 default: FUNC ARGS, \
377 long double: FUNC ## l ARGS, \
378 _Float128: FUNC ## f128 ARGS)
379 # else
380 # define __MATH_TG(TG_ARG, FUNC, ARGS) \
381 __builtin_choose_expr \
382 (__builtin_types_compatible_p (__typeof (TG_ARG), float), \
383 FUNC ## f ARGS, \
384 __builtin_choose_expr \
385 (__builtin_types_compatible_p (__typeof (TG_ARG), double), \
386 FUNC ARGS, \
387 __builtin_choose_expr \
388 (__builtin_types_compatible_p (__typeof (TG_ARG), long double), \
389 FUNC ## l ARGS, \
390 FUNC ## f128 ARGS)))
391 # endif
392 #else
393 # define __MATH_TG(TG_ARG, FUNC, ARGS) \
394 (sizeof (TG_ARG) == sizeof (float) \
395 ? FUNC ## f ARGS \
396 : sizeof (TG_ARG) == sizeof (double) \
397 ? FUNC ARGS \
398 : FUNC ## l ARGS)
399 #endif
400
401 /* ISO C99 defines some generic macros which work on any data type. */
402 #ifdef __USE_ISOC99
403
404 /* All floating-point numbers can be put in one of these categories. */
405 enum
406 {
407 FP_NAN =
408 # define FP_NAN 0
409 FP_NAN,
410 FP_INFINITE =
411 # define FP_INFINITE 1
412 FP_INFINITE,
413 FP_ZERO =
414 # define FP_ZERO 2
415 FP_ZERO,
416 FP_SUBNORMAL =
417 # define FP_SUBNORMAL 3
418 FP_SUBNORMAL,
419 FP_NORMAL =
420 # define FP_NORMAL 4
421 FP_NORMAL
422 };
423
424 /* GCC bug 66462 means we cannot use the math builtins with -fsignaling-nan,
425 so disable builtins if this is enabled. When fixed in a newer GCC,
426 the __SUPPORT_SNAN__ check may be skipped for those versions. */
427
428 /* Return number of classification appropriate for X. */
429 # if __GNUC_PREREQ (4,4) && !defined __SUPPORT_SNAN__ \
430 && !defined __OPTIMIZE_SIZE__
431 # define fpclassify(x) __builtin_fpclassify (FP_NAN, FP_INFINITE, \
432 FP_NORMAL, FP_SUBNORMAL, FP_ZERO, x)
433 # else
434 # define fpclassify(x) __MATH_TG ((x), __fpclassify, (x))
435 # endif
436
437 /* Return nonzero value if sign of X is negative. */
438 # if __GNUC_PREREQ (6,0)
439 # define signbit(x) __builtin_signbit (x)
440 # elif __GNUC_PREREQ (4,0)
441 # define signbit(x) __MATH_TG ((x), __builtin_signbit, (x))
442 # else
443 # define signbit(x) __MATH_TG ((x), __signbit, (x))
444 # endif
445
446 /* Return nonzero value if X is not +-Inf or NaN. */
447 # if __GNUC_PREREQ (4,4) && !defined __SUPPORT_SNAN__
448 # define isfinite(x) __builtin_isfinite (x)
449 # else
450 # define isfinite(x) __MATH_TG ((x), __finite, (x))
451 # endif
452
453 /* Return nonzero value if X is neither zero, subnormal, Inf, nor NaN. */
454 # if __GNUC_PREREQ (4,4) && !defined __SUPPORT_SNAN__
455 # define isnormal(x) __builtin_isnormal (x)
456 # else
457 # define isnormal(x) (fpclassify (x) == FP_NORMAL)
458 # endif
459
460 /* Return nonzero value if X is a NaN. We could use `fpclassify' but
461 we already have this functions `__isnan' and it is faster. */
462 # if __GNUC_PREREQ (4,4) && !defined __SUPPORT_SNAN__
463 # define isnan(x) __builtin_isnan (x)
464 # else
465 # define isnan(x) __MATH_TG ((x), __isnan, (x))
466 # endif
467
468 /* Return nonzero value if X is positive or negative infinity. */
469 # if __HAVE_DISTINCT_FLOAT128 && !__GNUC_PREREQ (7,0) \
470 && !defined __SUPPORT_SNAN__ && !defined __cplusplus
471 /* Since __builtin_isinf_sign is broken for float128 before GCC 7.0,
472 use the helper function, __isinff128, with older compilers. This is
473 only provided for C mode, because in C++ mode, GCC has no support
474 for __builtin_types_compatible_p (and when in C++ mode, this macro is
475 not used anyway, because libstdc++ headers undefine it). */
476 # define isinf(x) \
477 (__builtin_types_compatible_p (__typeof (x), _Float128) \
478 ? __isinff128 (x) : __builtin_isinf_sign (x))
479 # elif __GNUC_PREREQ (4,4) && !defined __SUPPORT_SNAN__
480 # define isinf(x) __builtin_isinf_sign (x)
481 # else
482 # define isinf(x) __MATH_TG ((x), __isinf, (x))
483 # endif
484
485 /* Bitmasks for the math_errhandling macro. */
486 # define MATH_ERRNO 1 /* errno set by math functions. */
487 # define MATH_ERREXCEPT 2 /* Exceptions raised by math functions. */
488
489 /* By default all functions support both errno and exception handling.
490 In gcc's fast math mode and if inline functions are defined this
491 might not be true. */
492 # ifndef __FAST_MATH__
493 # define math_errhandling (MATH_ERRNO | MATH_ERREXCEPT)
494 # endif
495
496 #endif /* Use ISO C99. */
497
498 #if __GLIBC_USE (IEC_60559_BFP_EXT)
499 # include <bits/iscanonical.h>
500
501 /* Return nonzero value if X is a signaling NaN. */
502 # ifndef __cplusplus
503 # define issignaling(x) __MATH_TG ((x), __issignaling, (x))
504 # else
505 /* In C++ mode, __MATH_TG cannot be used, because it relies on
506 __builtin_types_compatible_p, which is a C-only builtin. On the
507 other hand, overloading provides the means to distinguish between
508 the floating-point types. The overloading resolution will match
509 the correct parameter (regardless of type qualifiers (i.e.: const
510 and volatile). */
511 extern "C++" {
512 inline int issignaling (float __val) { return __issignalingf (__val); }
513 inline int issignaling (double __val) { return __issignaling (__val); }
514 inline int
515 issignaling (long double __val)
516 {
517 # ifdef __NO_LONG_DOUBLE_MATH
518 return __issignaling (__val);
519 # else
520 return __issignalingl (__val);
521 # endif
522 }
523 # if __HAVE_DISTINCT_FLOAT128
524 inline int issignaling (_Float128 __val) { return __issignalingf128 (__val); }
525 # endif
526 } /* extern C++ */
527 # endif
528
529 /* Return nonzero value if X is subnormal. */
530 # define issubnormal(x) (fpclassify (x) == FP_SUBNORMAL)
531
532 /* Return nonzero value if X is zero. */
533 # ifndef __cplusplus
534 # ifdef __SUPPORT_SNAN__
535 # define iszero(x) (fpclassify (x) == FP_ZERO)
536 # else
537 # define iszero(x) (((__typeof (x)) (x)) == 0)
538 # endif
539 # else /* __cplusplus */
540 extern "C++" {
541 # ifdef __SUPPORT_SNAN__
542 inline int
543 iszero (float __val)
544 {
545 return __fpclassifyf (__val) == FP_ZERO;
546 }
547 inline int
548 iszero (double __val)
549 {
550 return __fpclassify (__val) == FP_ZERO;
551 }
552 inline int
553 iszero (long double __val)
554 {
555 # ifdef __NO_LONG_DOUBLE_MATH
556 return __fpclassify (__val) == FP_ZERO;
557 # else
558 return __fpclassifyl (__val) == FP_ZERO;
559 # endif
560 }
561 # if __HAVE_DISTINCT_FLOAT128
562 inline int
563 iszero (_Float128 __val)
564 {
565 return __fpclassifyf128 (__val) == FP_ZERO;
566 }
567 # endif
568 # else
569 template <class __T> inline bool
570 iszero (__T __val)
571 {
572 return __val == 0;
573 }
574 # endif
575 } /* extern C++ */
576 # endif /* __cplusplus */
577 #endif /* Use IEC_60559_BFP_EXT. */
578
579 #ifdef __USE_XOPEN
580 /* X/Open wants another strange constant. */
581 # define MAXFLOAT 3.40282347e+38F
582 #endif
583
584
585 /* Some useful constants. */
586 #if defined __USE_MISC || defined __USE_XOPEN
587 # define M_E 2.7182818284590452354 /* e */
588 # define M_LOG2E 1.4426950408889634074 /* log_2 e */
589 # define M_LOG10E 0.43429448190325182765 /* log_10 e */
590 # define M_LN2 0.69314718055994530942 /* log_e 2 */
591 # define M_LN10 2.30258509299404568402 /* log_e 10 */
592 # define M_PI 3.14159265358979323846 /* pi */
593 # define M_PI_2 1.57079632679489661923 /* pi/2 */
594 # define M_PI_4 0.78539816339744830962 /* pi/4 */
595 # define M_1_PI 0.31830988618379067154 /* 1/pi */
596 # define M_2_PI 0.63661977236758134308 /* 2/pi */
597 # define M_2_SQRTPI 1.12837916709551257390 /* 2/sqrt(pi) */
598 # define M_SQRT2 1.41421356237309504880 /* sqrt(2) */
599 # define M_SQRT1_2 0.70710678118654752440 /* 1/sqrt(2) */
600 #endif
601
602 /* The above constants are not adequate for computation using `long double's.
603 Therefore we provide as an extension constants with similar names as a
604 GNU extension. Provide enough digits for the 128-bit IEEE quad. */
605 #ifdef __USE_GNU
606 # define M_El 2.718281828459045235360287471352662498L /* e */
607 # define M_LOG2El 1.442695040888963407359924681001892137L /* log_2 e */
608 # define M_LOG10El 0.434294481903251827651128918916605082L /* log_10 e */
609 # define M_LN2l 0.693147180559945309417232121458176568L /* log_e 2 */
610 # define M_LN10l 2.302585092994045684017991454684364208L /* log_e 10 */
611 # define M_PIl 3.141592653589793238462643383279502884L /* pi */
612 # define M_PI_2l 1.570796326794896619231321691639751442L /* pi/2 */
613 # define M_PI_4l 0.785398163397448309615660845819875721L /* pi/4 */
614 # define M_1_PIl 0.318309886183790671537767526745028724L /* 1/pi */
615 # define M_2_PIl 0.636619772367581343075535053490057448L /* 2/pi */
616 # define M_2_SQRTPIl 1.128379167095512573896158903121545172L /* 2/sqrt(pi) */
617 # define M_SQRT2l 1.414213562373095048801688724209698079L /* sqrt(2) */
618 # define M_SQRT1_2l 0.707106781186547524400844362104849039L /* 1/sqrt(2) */
619 #endif
620
621 #if __HAVE_FLOAT128 && defined __USE_GNU
622 # define M_Ef128 __f128 (2.718281828459045235360287471352662498) /* e */
623 # define M_LOG2Ef128 __f128 (1.442695040888963407359924681001892137) /* log_2 e */
624 # define M_LOG10Ef128 __f128 (0.434294481903251827651128918916605082) /* log_10 e */
625 # define M_LN2f128 __f128 (0.693147180559945309417232121458176568) /* log_e 2 */
626 # define M_LN10f128 __f128 (2.302585092994045684017991454684364208) /* log_e 10 */
627 # define M_PIf128 __f128 (3.141592653589793238462643383279502884) /* pi */
628 # define M_PI_2f128 __f128 (1.570796326794896619231321691639751442) /* pi/2 */
629 # define M_PI_4f128 __f128 (0.785398163397448309615660845819875721) /* pi/4 */
630 # define M_1_PIf128 __f128 (0.318309886183790671537767526745028724) /* 1/pi */
631 # define M_2_PIf128 __f128 (0.636619772367581343075535053490057448) /* 2/pi */
632 # define M_2_SQRTPIf128 __f128 (1.128379167095512573896158903121545172) /* 2/sqrt(pi) */
633 # define M_SQRT2f128 __f128 (1.414213562373095048801688724209698079) /* sqrt(2) */
634 # define M_SQRT1_2f128 __f128 (0.707106781186547524400844362104849039) /* 1/sqrt(2) */
635 #endif
636
637 /* When compiling in strict ISO C compatible mode we must not use the
638 inline functions since they, among other things, do not set the
639 `errno' variable correctly. */
640 #if defined __STRICT_ANSI__ && !defined __NO_MATH_INLINES
641 # define __NO_MATH_INLINES 1
642 #endif
643
644 #if defined __USE_ISOC99 && __GNUC_PREREQ(2,97)
645 /* ISO C99 defines some macros to compare number while taking care for
646 unordered numbers. Many FPUs provide special instructions to support
647 these operations. Generic support in GCC for these as builtins went
648 in before 3.0.0, but not all cpus added their patterns. We define
649 versions that use the builtins here, and <bits/mathinline.h> will
650 undef/redefine as appropriate for the specific GCC version in use. */
651 # define isgreater(x, y) __builtin_isgreater(x, y)
652 # define isgreaterequal(x, y) __builtin_isgreaterequal(x, y)
653 # define isless(x, y) __builtin_isless(x, y)
654 # define islessequal(x, y) __builtin_islessequal(x, y)
655 # define islessgreater(x, y) __builtin_islessgreater(x, y)
656 # define isunordered(u, v) __builtin_isunordered(u, v)
657 #endif
658
659 /* Get machine-dependent inline versions (if there are any). */
660 #ifdef __USE_EXTERN_INLINES
661 # include <bits/mathinline.h>
662 #endif
663
664 /* Define special entry points to use when the compiler got told to
665 only expect finite results. */
666 #if defined __FINITE_MATH_ONLY__ && __FINITE_MATH_ONLY__ > 0
667
668 /* Include bits/math-finite.h for double. */
669 # define _Mdouble_ double
670 # define __MATH_DECLARING_DOUBLE 1
671 # define __MATH_DECLARING_FLOATN 0
672 # define __REDIRFROM_X(function, reentrant) \
673 function ## reentrant
674 # define __REDIRTO_X(function, reentrant) \
675 __ ## function ## reentrant ## _finite
676 # include <bits/math-finite.h>
677 # undef _Mdouble_
678 # undef __MATH_DECLARING_DOUBLE
679 # undef __MATH_DECLARING_FLOATN
680 # undef __REDIRFROM_X
681 # undef __REDIRTO_X
682
683 /* When __USE_ISOC99 is defined, include math-finite for float and
684 long double, as well. */
685 # ifdef __USE_ISOC99
686
687 /* Include bits/math-finite.h for float. */
688 # define _Mdouble_ float
689 # define __MATH_DECLARING_DOUBLE 0
690 # define __MATH_DECLARING_FLOATN 0
691 # define __REDIRFROM_X(function, reentrant) \
692 function ## f ## reentrant
693 # define __REDIRTO_X(function, reentrant) \
694 __ ## function ## f ## reentrant ## _finite
695 # include <bits/math-finite.h>
696 # undef _Mdouble_
697 # undef __MATH_DECLARING_DOUBLE
698 # undef __MATH_DECLARING_FLOATN
699 # undef __REDIRFROM_X
700 # undef __REDIRTO_X
701
702 /* Include bits/math-finite.h for long double. */
703 # ifdef __MATH_DECLARE_LDOUBLE
704 # define _Mdouble_ long double
705 # define __MATH_DECLARING_DOUBLE 0
706 # define __MATH_DECLARING_FLOATN 0
707 # define __REDIRFROM_X(function, reentrant) \
708 function ## l ## reentrant
709 # ifdef __NO_LONG_DOUBLE_MATH
710 # define __REDIRTO_X(function, reentrant) \
711 __ ## function ## reentrant ## _finite
712 # else
713 # define __REDIRTO_X(function, reentrant) \
714 __ ## function ## l ## reentrant ## _finite
715 # endif
716 # include <bits/math-finite.h>
717 # undef _Mdouble_
718 # undef __MATH_DECLARING_DOUBLE
719 # undef __MATH_DECLARING_FLOATN
720 # undef __REDIRFROM_X
721 # undef __REDIRTO_X
722 # endif
723
724 # endif /* __USE_ISOC99. */
725
726 /* Include bits/math-finite.h for float128. */
727 # if (__HAVE_DISTINCT_FLOAT128 || (__HAVE_FLOAT128 && !defined _LIBC)) \
728 && __GLIBC_USE (IEC_60559_TYPES_EXT)
729 # define _Mdouble_ _Float128
730 # define __MATH_DECLARING_DOUBLE 0
731 # define __MATH_DECLARING_FLOATN 1
732 # define __REDIRFROM_X(function, reentrant) \
733 function ## f128 ## reentrant
734 # if __HAVE_DISTINCT_FLOAT128
735 # define __REDIRTO_X(function, reentrant) \
736 __ ## function ## f128 ## reentrant ## _finite
737 # else
738 # define __REDIRTO_X(function, reentrant) \
739 __ ## function ## l ## reentrant ## _finite
740 # endif
741 # include <bits/math-finite.h>
742 # undef _Mdouble_
743 # undef __MATH_DECLARING_DOUBLE
744 # undef __MATH_DECLARING_FLOATN
745 # undef __REDIRFROM_X
746 # undef __REDIRTO_X
747 # endif
748 #endif /* __FINITE_MATH_ONLY__ > 0. */
749
750 #ifdef __USE_ISOC99
751 /* If we've still got undefined comparison macros, provide defaults. */
752
753 /* Return nonzero value if X is greater than Y. */
754 # ifndef isgreater
755 # define isgreater(x, y) \
756 (__extension__ \
757 ({ __typeof__(x) __x = (x); __typeof__(y) __y = (y); \
758 !isunordered (__x, __y) && __x > __y; }))
759 # endif
760
761 /* Return nonzero value if X is greater than or equal to Y. */
762 # ifndef isgreaterequal
763 # define isgreaterequal(x, y) \
764 (__extension__ \
765 ({ __typeof__(x) __x = (x); __typeof__(y) __y = (y); \
766 !isunordered (__x, __y) && __x >= __y; }))
767 # endif
768
769 /* Return nonzero value if X is less than Y. */
770 # ifndef isless
771 # define isless(x, y) \
772 (__extension__ \
773 ({ __typeof__(x) __x = (x); __typeof__(y) __y = (y); \
774 !isunordered (__x, __y) && __x < __y; }))
775 # endif
776
777 /* Return nonzero value if X is less than or equal to Y. */
778 # ifndef islessequal
779 # define islessequal(x, y) \
780 (__extension__ \
781 ({ __typeof__(x) __x = (x); __typeof__(y) __y = (y); \
782 !isunordered (__x, __y) && __x <= __y; }))
783 # endif
784
785 /* Return nonzero value if either X is less than Y or Y is less than X. */
786 # ifndef islessgreater
787 # define islessgreater(x, y) \
788 (__extension__ \
789 ({ __typeof__(x) __x = (x); __typeof__(y) __y = (y); \
790 !isunordered (__x, __y) && (__x < __y || __y < __x); }))
791 # endif
792
793 /* Return nonzero value if arguments are unordered. */
794 # ifndef isunordered
795 # define isunordered(u, v) \
796 (__extension__ \
797 ({ __typeof__(u) __u = (u); __typeof__(v) __v = (v); \
798 fpclassify (__u) == FP_NAN || fpclassify (__v) == FP_NAN; }))
799 # endif
800
801 #endif
802
803 #if __GLIBC_USE (IEC_60559_BFP_EXT)
804 /* An expression whose type has the widest of the evaluation formats
805 of X and Y (which are of floating-point types). */
806 # if __FLT_EVAL_METHOD__ == 2 || __FLT_EVAL_METHOD__ > 64
807 # define __MATH_EVAL_FMT2(x, y) ((x) + (y) + 0.0L)
808 # elif __FLT_EVAL_METHOD__ == 1 || __FLT_EVAL_METHOD__ > 32
809 # define __MATH_EVAL_FMT2(x, y) ((x) + (y) + 0.0)
810 # else
811 # define __MATH_EVAL_FMT2(x, y) ((x) + (y))
812 # endif
813
814 /* Return X == Y but raising "invalid" and setting errno if X or Y is
815 a NaN. */
816 # define iseqsig(x, y) \
817 __MATH_TG (__MATH_EVAL_FMT2 (x, y), __iseqsig, ((x), (y)))
818 #endif
819
820 __END_DECLS
821
822
823 #endif /* math.h */