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