manual: improve string section wording
[glibc.git] / math / math.h
blob6dc0604132bfdcf04ac27a3b5325888973b8fec7
1 /* Declarations for math functions.
2 Copyright (C) 1991-2023 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 <https://www.gnu.org/licenses/>. */
20 * ISO C99 Standard: 7.12 Mathematics <math.h>
23 #ifndef _MATH_H
24 #define _MATH_H 1
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.
32 #endif
34 __BEGIN_DECLS
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 ())
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_FLOAT16 && __GLIBC_USE (IEC_60559_TYPES_EXT)
67 # define HUGE_VAL_F16 (__builtin_huge_valf16 ())
68 #endif
69 #if __HAVE_FLOAT32 && __GLIBC_USE (IEC_60559_TYPES_EXT)
70 # define HUGE_VAL_F32 (__builtin_huge_valf32 ())
71 #endif
72 #if __HAVE_FLOAT64 && __GLIBC_USE (IEC_60559_TYPES_EXT)
73 # define HUGE_VAL_F64 (__builtin_huge_valf64 ())
74 #endif
75 #if __HAVE_FLOAT128 && __GLIBC_USE (IEC_60559_TYPES_EXT)
76 # define HUGE_VAL_F128 (__builtin_huge_valf128 ())
77 #endif
78 #if __HAVE_FLOAT32X && __GLIBC_USE (IEC_60559_TYPES_EXT)
79 # define HUGE_VAL_F32X (__builtin_huge_valf32x ())
80 #endif
81 #if __HAVE_FLOAT64X && __GLIBC_USE (IEC_60559_TYPES_EXT)
82 # define HUGE_VAL_F64X (__builtin_huge_valf64x ())
83 #endif
84 #if __HAVE_FLOAT128X && __GLIBC_USE (IEC_60559_TYPES_EXT)
85 # define HUGE_VAL_F128X (__builtin_huge_valf128x ())
86 #endif
88 #ifdef __USE_ISOC99
89 /* IEEE positive infinity. */
90 # if __GNUC_PREREQ (3, 3)
91 # define INFINITY (__builtin_inff ())
92 # else
93 # define INFINITY HUGE_VALF
94 # endif
96 /* IEEE Not A Number. */
97 # if __GNUC_PREREQ (3, 3)
98 # define NAN (__builtin_nanf (""))
99 # else
100 /* This will raise an "invalid" exception outside static initializers,
101 but is the best that can be done in ISO C while remaining a
102 constant expression. */
103 # define NAN (0.0f / 0.0f)
104 # endif
105 #endif /* __USE_ISOC99 */
107 #if __GLIBC_USE (IEC_60559_BFP_EXT)
108 /* Signaling NaN macros, if supported. */
109 # if __GNUC_PREREQ (3, 3)
110 # define SNANF (__builtin_nansf (""))
111 # define SNAN (__builtin_nans (""))
112 # define SNANL (__builtin_nansl (""))
113 # endif
114 #endif
115 #if (__HAVE_FLOAT16 \
116 && __GLIBC_USE (IEC_60559_TYPES_EXT) \
117 && (defined __USE_GNU || !__GLIBC_USE (ISOC2X)))
118 # define SNANF16 (__builtin_nansf16 (""))
119 #endif
120 #if (__HAVE_FLOAT32 \
121 && __GLIBC_USE (IEC_60559_TYPES_EXT) \
122 && (defined __USE_GNU || !__GLIBC_USE (ISOC2X)))
123 # define SNANF32 (__builtin_nansf32 (""))
124 #endif
125 #if (__HAVE_FLOAT64 \
126 && __GLIBC_USE (IEC_60559_TYPES_EXT) \
127 && (defined __USE_GNU || !__GLIBC_USE (ISOC2X)))
128 # define SNANF64 (__builtin_nansf64 (""))
129 #endif
130 #if (__HAVE_FLOAT128 \
131 && __GLIBC_USE (IEC_60559_TYPES_EXT) \
132 && (defined __USE_GNU || !__GLIBC_USE (ISOC2X)))
133 # define SNANF128 (__builtin_nansf128 (""))
134 #endif
135 #if (__HAVE_FLOAT32X \
136 && __GLIBC_USE (IEC_60559_TYPES_EXT) \
137 && (defined __USE_GNU || !__GLIBC_USE (ISOC2X)))
138 # define SNANF32X (__builtin_nansf32x (""))
139 #endif
140 #if (__HAVE_FLOAT64X \
141 && __GLIBC_USE (IEC_60559_TYPES_EXT) \
142 && (defined __USE_GNU || !__GLIBC_USE (ISOC2X)))
143 # define SNANF64X (__builtin_nansf64x (""))
144 #endif
145 #if (__HAVE_FLOAT128X \
146 && __GLIBC_USE (IEC_60559_TYPES_EXT) \
147 && (defined __USE_GNU || !__GLIBC_USE (ISOC2X)))
148 # define SNANF128X (__builtin_nansf128x (""))
149 #endif
151 /* Get __GLIBC_FLT_EVAL_METHOD. */
152 #include <bits/flt-eval-method.h>
154 #ifdef __USE_ISOC99
155 /* Define the following typedefs.
157 float_t floating-point type at least as wide as `float' used
158 to evaluate `float' expressions
159 double_t floating-point type at least as wide as `double' used
160 to evaluate `double' expressions
162 # if __GLIBC_FLT_EVAL_METHOD == 0 || __GLIBC_FLT_EVAL_METHOD == 16
163 typedef float float_t;
164 typedef double double_t;
165 # elif __GLIBC_FLT_EVAL_METHOD == 1
166 typedef double float_t;
167 typedef double double_t;
168 # elif __GLIBC_FLT_EVAL_METHOD == 2
169 typedef long double float_t;
170 typedef long double double_t;
171 # elif __GLIBC_FLT_EVAL_METHOD == 32
172 typedef _Float32 float_t;
173 typedef double double_t;
174 # elif __GLIBC_FLT_EVAL_METHOD == 33
175 typedef _Float32x float_t;
176 typedef _Float32x double_t;
177 # elif __GLIBC_FLT_EVAL_METHOD == 64
178 typedef _Float64 float_t;
179 typedef _Float64 double_t;
180 # elif __GLIBC_FLT_EVAL_METHOD == 65
181 typedef _Float64x float_t;
182 typedef _Float64x double_t;
183 # elif __GLIBC_FLT_EVAL_METHOD == 128
184 typedef _Float128 float_t;
185 typedef _Float128 double_t;
186 # elif __GLIBC_FLT_EVAL_METHOD == 129
187 typedef _Float128x float_t;
188 typedef _Float128x double_t;
189 # else
190 # error "Unknown __GLIBC_FLT_EVAL_METHOD"
191 # endif
192 #endif
194 /* Define macros for the return values of ilogb and llogb, based on
195 __FP_LOGB0_IS_MIN and __FP_LOGBNAN_IS_MIN.
197 FP_ILOGB0 Expands to a value returned by `ilogb (0.0)'.
198 FP_ILOGBNAN Expands to a value returned by `ilogb (NAN)'.
199 FP_LLOGB0 Expands to a value returned by `llogb (0.0)'.
200 FP_LLOGBNAN Expands to a value returned by `llogb (NAN)'.
204 #include <bits/fp-logb.h>
205 #ifdef __USE_ISOC99
206 # if __FP_LOGB0_IS_MIN
207 # define FP_ILOGB0 (-2147483647 - 1)
208 # else
209 # define FP_ILOGB0 (-2147483647)
210 # endif
211 # if __FP_LOGBNAN_IS_MIN
212 # define FP_ILOGBNAN (-2147483647 - 1)
213 # else
214 # define FP_ILOGBNAN 2147483647
215 # endif
216 #endif
217 #if __GLIBC_USE (IEC_60559_BFP_EXT_C2X)
218 # if __WORDSIZE == 32
219 # define __FP_LONG_MAX 0x7fffffffL
220 # else
221 # define __FP_LONG_MAX 0x7fffffffffffffffL
222 # endif
223 # if __FP_LOGB0_IS_MIN
224 # define FP_LLOGB0 (-__FP_LONG_MAX - 1)
225 # else
226 # define FP_LLOGB0 (-__FP_LONG_MAX)
227 # endif
228 # if __FP_LOGBNAN_IS_MIN
229 # define FP_LLOGBNAN (-__FP_LONG_MAX - 1)
230 # else
231 # define FP_LLOGBNAN __FP_LONG_MAX
232 # endif
233 #endif
235 /* Get the architecture specific values describing the floating-point
236 evaluation. The following symbols will get defined:
238 FP_FAST_FMA
239 FP_FAST_FMAF
240 FP_FAST_FMAL
241 If defined it indicates that the `fma' function
242 generally executes about as fast as a multiply and an add.
243 This macro is defined only iff the `fma' function is
244 implemented directly with a hardware multiply-add instructions.
247 #include <bits/fp-fast.h>
249 #if __GLIBC_USE (IEC_60559_BFP_EXT_C2X)
250 /* Rounding direction macros for fromfp functions. */
251 enum
253 FP_INT_UPWARD =
254 # define FP_INT_UPWARD 0
255 FP_INT_UPWARD,
256 FP_INT_DOWNWARD =
257 # define FP_INT_DOWNWARD 1
258 FP_INT_DOWNWARD,
259 FP_INT_TOWARDZERO =
260 # define FP_INT_TOWARDZERO 2
261 FP_INT_TOWARDZERO,
262 FP_INT_TONEARESTFROMZERO =
263 # define FP_INT_TONEARESTFROMZERO 3
264 FP_INT_TONEARESTFROMZERO,
265 FP_INT_TONEAREST =
266 # define FP_INT_TONEAREST 4
267 FP_INT_TONEAREST,
269 #endif
271 /* The file <bits/mathcalls.h> contains the prototypes for all the
272 actual math functions. These macros are used for those prototypes,
273 so we can easily declare each function as both `name' and `__name',
274 and can declare the float versions `namef' and `__namef'. */
276 #define __SIMD_DECL(function) __CONCAT (__DECL_SIMD_, function)
278 #define __MATHCALL_VEC(function, suffix, args) \
279 __SIMD_DECL (__MATH_PRECNAME (function, suffix)) \
280 __MATHCALL (function, suffix, args)
282 #define __MATHDECL_VEC(type, function,suffix, args) \
283 __SIMD_DECL (__MATH_PRECNAME (function, suffix)) \
284 __MATHDECL(type, function,suffix, args)
286 #define __MATHCALL(function,suffix, args) \
287 __MATHDECL (_Mdouble_,function,suffix, args)
288 #define __MATHDECL(type, function,suffix, args) \
289 __MATHDECL_1(type, function,suffix, args); \
290 __MATHDECL_1(type, __CONCAT(__,function),suffix, args)
291 #define __MATHCALLX(function,suffix, args, attrib) \
292 __MATHDECLX (_Mdouble_,function,suffix, args, attrib)
293 #define __MATHDECLX(type, function,suffix, args, attrib) \
294 __MATHDECL_1(type, function,suffix, args) __attribute__ (attrib); \
295 __MATHDECL_1(type, __CONCAT(__,function),suffix, args) __attribute__ (attrib)
296 #define __MATHDECL_1_IMPL(type, function, suffix, args) \
297 extern type __MATH_PRECNAME(function,suffix) args __THROW
298 #define __MATHDECL_1(type, function, suffix, args) \
299 __MATHDECL_1_IMPL(type, function, suffix, args)
300 /* Ignore the alias by default. The alias is only useful with
301 redirections. */
302 #define __MATHDECL_ALIAS(type, function, suffix, args, alias) \
303 __MATHDECL_1(type, function, suffix, args)
305 #define __MATHREDIR(type, function, suffix, args, to) \
306 extern type __REDIRECT_NTH (__MATH_PRECNAME (function, suffix), args, to)
308 #define _Mdouble_ double
309 #define __MATH_PRECNAME(name,r) __CONCAT(name,r)
310 #define __MATH_DECLARING_DOUBLE 1
311 #define __MATH_DECLARING_FLOATN 0
312 #include <bits/mathcalls-helper-functions.h>
313 #include <bits/mathcalls.h>
314 #undef _Mdouble_
315 #undef __MATH_PRECNAME
316 #undef __MATH_DECLARING_DOUBLE
317 #undef __MATH_DECLARING_FLOATN
319 #ifdef __USE_ISOC99
322 /* Include the file of declarations again, this time using `float'
323 instead of `double' and appending f to each function name. */
325 # define _Mdouble_ float
326 # define __MATH_PRECNAME(name,r) name##f##r
327 # define __MATH_DECLARING_DOUBLE 0
328 # define __MATH_DECLARING_FLOATN 0
329 # include <bits/mathcalls-helper-functions.h>
330 # include <bits/mathcalls.h>
331 # undef _Mdouble_
332 # undef __MATH_PRECNAME
333 # undef __MATH_DECLARING_DOUBLE
334 # undef __MATH_DECLARING_FLOATN
336 # if !(defined __NO_LONG_DOUBLE_MATH && defined _LIBC) \
337 || defined __LDBL_COMPAT \
338 || defined _LIBC_TEST
339 # ifdef __LDBL_COMPAT
341 # ifdef __USE_ISOC99
342 extern float __nldbl_nexttowardf (float __x, long double __y)
343 __THROW __attribute__ ((__const__));
344 # ifdef __REDIRECT_NTH
345 extern float __REDIRECT_NTH (nexttowardf, (float __x, long double __y),
346 __nldbl_nexttowardf)
347 __attribute__ ((__const__));
348 extern double __REDIRECT_NTH (nexttoward, (double __x, long double __y),
349 nextafter) __attribute__ ((__const__));
350 extern long double __REDIRECT_NTH (nexttowardl,
351 (long double __x, long double __y),
352 nextafter) __attribute__ ((__const__));
353 # endif
354 # endif
356 # undef __MATHDECL_1
357 # define __MATHDECL_1(type, function,suffix, args) \
358 __MATHREDIR(type, function, suffix, args, __CONCAT(function,suffix))
360 # elif __LDOUBLE_REDIRECTS_TO_FLOAT128_ABI == 1
361 # ifdef __REDIRECT_NTH
362 # ifdef __USE_ISOC99
363 extern float __REDIRECT_NTH (nexttowardf, (float __x, long double __y),
364 __nexttowardf_to_ieee128)
365 __attribute__ ((__const__));
366 extern double __REDIRECT_NTH (nexttoward, (double __x, long double __y),
367 __nexttoward_to_ieee128)
368 __attribute__ ((__const__));
370 #define __dremieee128 __remainderieee128
371 #define __gammaieee128 __lgammaieee128
373 # endif
374 # endif
376 # undef __MATHDECL_1
377 # undef __MATHDECL_ALIAS
379 # define __REDIRTO(function, suffix) \
380 __ ## function ## ieee128 ## suffix
381 # define __REDIRTO_ALT(function, suffix) \
382 __ ## function ## f128 ## suffix
384 # define __MATHDECL_1(type, function, suffix, args) \
385 __MATHREDIR (type, function, suffix, args, __REDIRTO (function, suffix))
386 # define __MATHDECL_ALIAS(type, function, suffix, args, alias) \
387 __MATHREDIR (type, function, suffix, args, __REDIRTO_ALT (alias, suffix))
388 # endif
390 /* Include the file of declarations again, this time using `long double'
391 instead of `double' and appending l to each function name. */
393 # define _Mdouble_ long double
394 # define __MATH_PRECNAME(name,r) name##l##r
395 # define __MATH_DECLARING_DOUBLE 0
396 # define __MATH_DECLARING_FLOATN 0
397 # define __MATH_DECLARE_LDOUBLE 1
398 # include <bits/mathcalls-helper-functions.h>
399 # include <bits/mathcalls.h>
401 # undef _Mdouble_
402 # undef __MATH_PRECNAME
403 # undef __MATH_DECLARING_DOUBLE
404 # undef __MATH_DECLARING_FLOATN
406 # if defined __LDBL_COMPAT \
407 || __LDOUBLE_REDIRECTS_TO_FLOAT128_ABI == 1
408 # undef __REDIRTO
409 # undef __REDIRTO_ALT
410 # undef __MATHDECL_1
411 # undef __MATHDECL_ALIAS
412 # define __MATHDECL_1(type, function, suffix, args) \
413 __MATHDECL_1_IMPL(type, function, suffix, args)
414 # define __MATHDECL_ALIAS(type, function, suffix, args, alias) \
415 __MATHDECL_1(type, function, suffix, args)
416 # endif
417 # endif /* !(__NO_LONG_DOUBLE_MATH && _LIBC) || __LDBL_COMPAT */
419 #endif /* Use ISO C99. */
421 /* Include the file of declarations for _FloatN and _FloatNx
422 types. */
424 #if __HAVE_DISTINCT_FLOAT16 || (__HAVE_FLOAT16 && !defined _LIBC)
425 # define _Mdouble_ _Float16
426 # define __MATH_PRECNAME(name,r) name##f16##r
427 # define __MATH_DECLARING_DOUBLE 0
428 # define __MATH_DECLARING_FLOATN 1
429 # if __HAVE_DISTINCT_FLOAT16
430 # include <bits/mathcalls-helper-functions.h>
431 # endif
432 # if __GLIBC_USE (IEC_60559_TYPES_EXT)
433 # include <bits/mathcalls.h>
434 # endif
435 # undef _Mdouble_
436 # undef __MATH_PRECNAME
437 # undef __MATH_DECLARING_DOUBLE
438 # undef __MATH_DECLARING_FLOATN
439 #endif /* __HAVE_DISTINCT_FLOAT16 || (__HAVE_FLOAT16 && !_LIBC). */
441 #if __HAVE_DISTINCT_FLOAT32 || (__HAVE_FLOAT32 && !defined _LIBC)
442 # define _Mdouble_ _Float32
443 # define __MATH_PRECNAME(name,r) name##f32##r
444 # define __MATH_DECLARING_DOUBLE 0
445 # define __MATH_DECLARING_FLOATN 1
446 # if __HAVE_DISTINCT_FLOAT32
447 # include <bits/mathcalls-helper-functions.h>
448 # endif
449 # if __GLIBC_USE (IEC_60559_TYPES_EXT)
450 # include <bits/mathcalls.h>
451 # endif
452 # undef _Mdouble_
453 # undef __MATH_PRECNAME
454 # undef __MATH_DECLARING_DOUBLE
455 # undef __MATH_DECLARING_FLOATN
456 #endif /* __HAVE_DISTINCT_FLOAT32 || (__HAVE_FLOAT32 && !_LIBC). */
458 #if __HAVE_DISTINCT_FLOAT64 || (__HAVE_FLOAT64 && !defined _LIBC)
459 # define _Mdouble_ _Float64
460 # define __MATH_PRECNAME(name,r) name##f64##r
461 # define __MATH_DECLARING_DOUBLE 0
462 # define __MATH_DECLARING_FLOATN 1
463 # if __HAVE_DISTINCT_FLOAT64
464 # include <bits/mathcalls-helper-functions.h>
465 # endif
466 # if __GLIBC_USE (IEC_60559_TYPES_EXT)
467 # include <bits/mathcalls.h>
468 # endif
469 # undef _Mdouble_
470 # undef __MATH_PRECNAME
471 # undef __MATH_DECLARING_DOUBLE
472 # undef __MATH_DECLARING_FLOATN
473 #endif /* __HAVE_DISTINCT_FLOAT64 || (__HAVE_FLOAT64 && !_LIBC). */
475 #if __HAVE_DISTINCT_FLOAT128 || (__HAVE_FLOAT128 && !defined _LIBC)
476 # define _Mdouble_ _Float128
477 # define __MATH_PRECNAME(name,r) name##f128##r
478 # define __MATH_DECLARING_DOUBLE 0
479 # define __MATH_DECLARING_FLOATN 1
480 # if __HAVE_DISTINCT_FLOAT128
481 # include <bits/mathcalls-helper-functions.h>
482 # endif
483 # if __GLIBC_USE (IEC_60559_TYPES_EXT)
484 # include <bits/mathcalls.h>
485 # endif
486 # undef _Mdouble_
487 # undef __MATH_PRECNAME
488 # undef __MATH_DECLARING_DOUBLE
489 # undef __MATH_DECLARING_FLOATN
490 #endif /* __HAVE_DISTINCT_FLOAT128 || (__HAVE_FLOAT128 && !_LIBC). */
492 #if __HAVE_DISTINCT_FLOAT32X || (__HAVE_FLOAT32X && !defined _LIBC)
493 # define _Mdouble_ _Float32x
494 # define __MATH_PRECNAME(name,r) name##f32x##r
495 # define __MATH_DECLARING_DOUBLE 0
496 # define __MATH_DECLARING_FLOATN 1
497 # if __HAVE_DISTINCT_FLOAT32X
498 # include <bits/mathcalls-helper-functions.h>
499 # endif
500 # if __GLIBC_USE (IEC_60559_TYPES_EXT)
501 # include <bits/mathcalls.h>
502 # endif
503 # undef _Mdouble_
504 # undef __MATH_PRECNAME
505 # undef __MATH_DECLARING_DOUBLE
506 # undef __MATH_DECLARING_FLOATN
507 #endif /* __HAVE_DISTINCT_FLOAT32X || (__HAVE_FLOAT32X && !_LIBC). */
509 #if __HAVE_DISTINCT_FLOAT64X || (__HAVE_FLOAT64X && !defined _LIBC)
510 # define _Mdouble_ _Float64x
511 # define __MATH_PRECNAME(name,r) name##f64x##r
512 # define __MATH_DECLARING_DOUBLE 0
513 # define __MATH_DECLARING_FLOATN 1
514 # if __HAVE_DISTINCT_FLOAT64X
515 # include <bits/mathcalls-helper-functions.h>
516 # endif
517 # if __GLIBC_USE (IEC_60559_TYPES_EXT)
518 # include <bits/mathcalls.h>
519 # endif
520 # undef _Mdouble_
521 # undef __MATH_PRECNAME
522 # undef __MATH_DECLARING_DOUBLE
523 # undef __MATH_DECLARING_FLOATN
524 #endif /* __HAVE_DISTINCT_FLOAT64X || (__HAVE_FLOAT64X && !_LIBC). */
526 #if __HAVE_DISTINCT_FLOAT128X || (__HAVE_FLOAT128X && !defined _LIBC)
527 # define _Mdouble_ _Float128x
528 # define __MATH_PRECNAME(name,r) name##f128x##r
529 # define __MATH_DECLARING_DOUBLE 0
530 # define __MATH_DECLARING_FLOATN 1
531 # if __HAVE_DISTINCT_FLOAT128X
532 # include <bits/mathcalls-helper-functions.h>
533 # endif
534 # if __GLIBC_USE (IEC_60559_TYPES_EXT)
535 # include <bits/mathcalls.h>
536 # endif
537 # undef _Mdouble_
538 # undef __MATH_PRECNAME
539 # undef __MATH_DECLARING_DOUBLE
540 # undef __MATH_DECLARING_FLOATN
541 #endif /* __HAVE_DISTINCT_FLOAT128X || (__HAVE_FLOAT128X && !_LIBC). */
543 #undef __MATHDECL_1_IMPL
544 #undef __MATHDECL_1
545 #undef __MATHDECL_ALIAS
546 #undef __MATHDECL
547 #undef __MATHCALL
549 /* Declare functions returning a narrower type. */
550 #define __MATHCALL_NARROW_ARGS_1 (_Marg_ __x)
551 #define __MATHCALL_NARROW_ARGS_2 (_Marg_ __x, _Marg_ __y)
552 #define __MATHCALL_NARROW_ARGS_3 (_Marg_ __x, _Marg_ __y, _Marg_ __z)
553 #define __MATHCALL_NARROW_NORMAL(func, nargs) \
554 extern _Mret_ func __MATHCALL_NARROW_ARGS_ ## nargs __THROW
555 #define __MATHCALL_NARROW_REDIR(func, redir, nargs) \
556 extern _Mret_ __REDIRECT_NTH (func, __MATHCALL_NARROW_ARGS_ ## nargs, \
557 redir)
558 #define __MATHCALL_NARROW(func, redir, nargs) \
559 __MATHCALL_NARROW_NORMAL (func, nargs)
561 #if __GLIBC_USE (IEC_60559_BFP_EXT_C2X)
563 # define _Mret_ float
564 # define _Marg_ double
565 # define __MATHCALL_NAME(name) f ## name
566 # include <bits/mathcalls-narrow.h>
567 # undef _Mret_
568 # undef _Marg_
569 # undef __MATHCALL_NAME
571 # define _Mret_ float
572 # define _Marg_ long double
573 # define __MATHCALL_NAME(name) f ## name ## l
574 # ifdef __LDBL_COMPAT
575 # define __MATHCALL_REDIR_NAME(name) f ## name
576 # define __MATHCALL_REDIR_NAME2(name) f ## name
577 # undef __MATHCALL_NARROW
578 # define __MATHCALL_NARROW(func, redir, nargs) \
579 __MATHCALL_NARROW_REDIR (func, redir, nargs)
580 # elif __LDOUBLE_REDIRECTS_TO_FLOAT128_ABI == 1
581 # define __MATHCALL_REDIR_NAME(name) __ ## f32 ## name ## ieee128
582 # define __MATHCALL_REDIR_NAME2(name) __ ## f32 ## name ## ieee128
583 # undef __MATHCALL_NARROW
584 # define __MATHCALL_NARROW(func, redir, nargs) \
585 __MATHCALL_NARROW_REDIR (func, redir, nargs)
586 # endif
587 # include <bits/mathcalls-narrow.h>
588 # undef _Mret_
589 # undef _Marg_
590 # undef __MATHCALL_NAME
591 # if defined __LDBL_COMPAT \
592 || __LDOUBLE_REDIRECTS_TO_FLOAT128_ABI == 1
593 # undef __MATHCALL_REDIR_NAME
594 # undef __MATHCALL_REDIR_NAME2
595 # undef __MATHCALL_NARROW
596 # define __MATHCALL_NARROW(func, redir, nargs) \
597 __MATHCALL_NARROW_NORMAL (func, nargs)
598 # endif
600 # define _Mret_ double
601 # define _Marg_ long double
602 # define __MATHCALL_NAME(name) d ## name ## l
603 # ifdef __LDBL_COMPAT
604 # define __MATHCALL_REDIR_NAME(name) __nldbl_d ## name ## l
605 # define __MATHCALL_REDIR_NAME2(name) name
606 # undef __MATHCALL_NARROW
607 # define __MATHCALL_NARROW(func, redir, nargs) \
608 __MATHCALL_NARROW_REDIR (func, redir, nargs)
609 # elif __LDOUBLE_REDIRECTS_TO_FLOAT128_ABI == 1
610 # define __MATHCALL_REDIR_NAME(name) __ ## f64 ## name ## ieee128
611 # define __MATHCALL_REDIR_NAME2(name) __ ## f64 ## name ## ieee128
612 # undef __MATHCALL_NARROW
613 # define __MATHCALL_NARROW(func, redir, nargs) \
614 __MATHCALL_NARROW_REDIR (func, redir, nargs)
615 # endif
616 # include <bits/mathcalls-narrow.h>
617 # undef _Mret_
618 # undef _Marg_
619 # undef __MATHCALL_NAME
620 # if defined __LDBL_COMPAT \
621 || __LDOUBLE_REDIRECTS_TO_FLOAT128_ABI == 1
622 # undef __MATHCALL_REDIR_NAME
623 # undef __MATHCALL_REDIR_NAME2
624 # undef __MATHCALL_NARROW
625 # define __MATHCALL_NARROW(func, redir, nargs) \
626 __MATHCALL_NARROW_NORMAL (func, nargs)
627 # endif
629 #endif
631 #if __GLIBC_USE (IEC_60559_TYPES_EXT)
633 # if __HAVE_FLOAT16 && __HAVE_FLOAT32
634 # define _Mret_ _Float16
635 # define _Marg_ _Float32
636 # define __MATHCALL_NAME(name) f16 ## name ## f32
637 # include <bits/mathcalls-narrow.h>
638 # undef _Mret_
639 # undef _Marg_
640 # undef __MATHCALL_NAME
641 # endif
643 # if __HAVE_FLOAT16 && __HAVE_FLOAT32X
644 # define _Mret_ _Float16
645 # define _Marg_ _Float32x
646 # define __MATHCALL_NAME(name) f16 ## name ## f32x
647 # include <bits/mathcalls-narrow.h>
648 # undef _Mret_
649 # undef _Marg_
650 # undef __MATHCALL_NAME
651 # endif
653 # if __HAVE_FLOAT16 && __HAVE_FLOAT64
654 # define _Mret_ _Float16
655 # define _Marg_ _Float64
656 # define __MATHCALL_NAME(name) f16 ## name ## f64
657 # include <bits/mathcalls-narrow.h>
658 # undef _Mret_
659 # undef _Marg_
660 # undef __MATHCALL_NAME
661 # endif
663 # if __HAVE_FLOAT16 && __HAVE_FLOAT64X
664 # define _Mret_ _Float16
665 # define _Marg_ _Float64x
666 # define __MATHCALL_NAME(name) f16 ## name ## f64x
667 # include <bits/mathcalls-narrow.h>
668 # undef _Mret_
669 # undef _Marg_
670 # undef __MATHCALL_NAME
671 # endif
673 # if __HAVE_FLOAT16 && __HAVE_FLOAT128
674 # define _Mret_ _Float16
675 # define _Marg_ _Float128
676 # define __MATHCALL_NAME(name) f16 ## name ## f128
677 # include <bits/mathcalls-narrow.h>
678 # undef _Mret_
679 # undef _Marg_
680 # undef __MATHCALL_NAME
681 # endif
683 # if __HAVE_FLOAT16 && __HAVE_FLOAT128X
684 # define _Mret_ _Float16
685 # define _Marg_ _Float128x
686 # define __MATHCALL_NAME(name) f16 ## name ## f128x
687 # include <bits/mathcalls-narrow.h>
688 # undef _Mret_
689 # undef _Marg_
690 # undef __MATHCALL_NAME
691 # endif
693 # if __HAVE_FLOAT32 && __HAVE_FLOAT32X
694 # define _Mret_ _Float32
695 # define _Marg_ _Float32x
696 # define __MATHCALL_NAME(name) f32 ## name ## f32x
697 # include <bits/mathcalls-narrow.h>
698 # undef _Mret_
699 # undef _Marg_
700 # undef __MATHCALL_NAME
701 # endif
703 # if __HAVE_FLOAT32 && __HAVE_FLOAT64
704 # define _Mret_ _Float32
705 # define _Marg_ _Float64
706 # define __MATHCALL_NAME(name) f32 ## name ## f64
707 # include <bits/mathcalls-narrow.h>
708 # undef _Mret_
709 # undef _Marg_
710 # undef __MATHCALL_NAME
711 # endif
713 # if __HAVE_FLOAT32 && __HAVE_FLOAT64X
714 # define _Mret_ _Float32
715 # define _Marg_ _Float64x
716 # define __MATHCALL_NAME(name) f32 ## name ## f64x
717 # include <bits/mathcalls-narrow.h>
718 # undef _Mret_
719 # undef _Marg_
720 # undef __MATHCALL_NAME
721 # endif
723 # if __HAVE_FLOAT32 && __HAVE_FLOAT128
724 # define _Mret_ _Float32
725 # define _Marg_ _Float128
726 # define __MATHCALL_NAME(name) f32 ## name ## f128
727 # include <bits/mathcalls-narrow.h>
728 # undef _Mret_
729 # undef _Marg_
730 # undef __MATHCALL_NAME
731 # endif
733 # if __HAVE_FLOAT32 && __HAVE_FLOAT128X
734 # define _Mret_ _Float32
735 # define _Marg_ _Float128x
736 # define __MATHCALL_NAME(name) f32 ## name ## f128x
737 # include <bits/mathcalls-narrow.h>
738 # undef _Mret_
739 # undef _Marg_
740 # undef __MATHCALL_NAME
741 # endif
743 # if __HAVE_FLOAT32X && __HAVE_FLOAT64
744 # define _Mret_ _Float32x
745 # define _Marg_ _Float64
746 # define __MATHCALL_NAME(name) f32x ## name ## f64
747 # include <bits/mathcalls-narrow.h>
748 # undef _Mret_
749 # undef _Marg_
750 # undef __MATHCALL_NAME
751 # endif
753 # if __HAVE_FLOAT32X && __HAVE_FLOAT64X
754 # define _Mret_ _Float32x
755 # define _Marg_ _Float64x
756 # define __MATHCALL_NAME(name) f32x ## name ## f64x
757 # include <bits/mathcalls-narrow.h>
758 # undef _Mret_
759 # undef _Marg_
760 # undef __MATHCALL_NAME
761 # endif
763 # if __HAVE_FLOAT32X && __HAVE_FLOAT128
764 # define _Mret_ _Float32x
765 # define _Marg_ _Float128
766 # define __MATHCALL_NAME(name) f32x ## name ## f128
767 # include <bits/mathcalls-narrow.h>
768 # undef _Mret_
769 # undef _Marg_
770 # undef __MATHCALL_NAME
771 # endif
773 # if __HAVE_FLOAT32X && __HAVE_FLOAT128X
774 # define _Mret_ _Float32x
775 # define _Marg_ _Float128x
776 # define __MATHCALL_NAME(name) f32x ## name ## f128x
777 # include <bits/mathcalls-narrow.h>
778 # undef _Mret_
779 # undef _Marg_
780 # undef __MATHCALL_NAME
781 # endif
783 # if __HAVE_FLOAT64 && __HAVE_FLOAT64X
784 # define _Mret_ _Float64
785 # define _Marg_ _Float64x
786 # define __MATHCALL_NAME(name) f64 ## name ## f64x
787 # include <bits/mathcalls-narrow.h>
788 # undef _Mret_
789 # undef _Marg_
790 # undef __MATHCALL_NAME
791 # endif
793 # if __HAVE_FLOAT64 && __HAVE_FLOAT128
794 # define _Mret_ _Float64
795 # define _Marg_ _Float128
796 # define __MATHCALL_NAME(name) f64 ## name ## f128
797 # include <bits/mathcalls-narrow.h>
798 # undef _Mret_
799 # undef _Marg_
800 # undef __MATHCALL_NAME
801 # endif
803 # if __HAVE_FLOAT64 && __HAVE_FLOAT128X
804 # define _Mret_ _Float64
805 # define _Marg_ _Float128x
806 # define __MATHCALL_NAME(name) f64 ## name ## f128x
807 # include <bits/mathcalls-narrow.h>
808 # undef _Mret_
809 # undef _Marg_
810 # undef __MATHCALL_NAME
811 # endif
813 # if __HAVE_FLOAT64X && __HAVE_FLOAT128
814 # define _Mret_ _Float64x
815 # define _Marg_ _Float128
816 # define __MATHCALL_NAME(name) f64x ## name ## f128
817 # include <bits/mathcalls-narrow.h>
818 # undef _Mret_
819 # undef _Marg_
820 # undef __MATHCALL_NAME
821 # endif
823 # if __HAVE_FLOAT64X && __HAVE_FLOAT128X
824 # define _Mret_ _Float64x
825 # define _Marg_ _Float128x
826 # define __MATHCALL_NAME(name) f64x ## name ## f128x
827 # include <bits/mathcalls-narrow.h>
828 # undef _Mret_
829 # undef _Marg_
830 # undef __MATHCALL_NAME
831 # endif
833 # if __HAVE_FLOAT128 && __HAVE_FLOAT128X
834 # define _Mret_ _Float128
835 # define _Marg_ _Float128x
836 # define __MATHCALL_NAME(name) f128 ## name ## f128x
837 # include <bits/mathcalls-narrow.h>
838 # undef _Mret_
839 # undef _Marg_
840 # undef __MATHCALL_NAME
841 # endif
843 #endif
845 #undef __MATHCALL_NARROW_ARGS_1
846 #undef __MATHCALL_NARROW_ARGS_2
847 #undef __MATHCALL_NARROW_ARGS_3
848 #undef __MATHCALL_NARROW_NORMAL
849 #undef __MATHCALL_NARROW_REDIR
850 #undef __MATHCALL_NARROW
852 #if defined __USE_MISC || defined __USE_XOPEN
853 /* This variable is used by `gamma' and `lgamma'. */
854 extern int signgam;
855 #endif
857 #if (__HAVE_DISTINCT_FLOAT16 \
858 || __HAVE_DISTINCT_FLOAT32 \
859 || __HAVE_DISTINCT_FLOAT64 \
860 || __HAVE_DISTINCT_FLOAT32X \
861 || __HAVE_DISTINCT_FLOAT64X \
862 || __HAVE_DISTINCT_FLOAT128X)
863 # error "Unsupported _FloatN or _FloatNx types for <math.h>."
864 #endif
866 /* Depending on the type of TG_ARG, call an appropriately suffixed
867 version of FUNC with arguments (including parentheses) ARGS.
868 Suffixed functions may not exist for long double if it has the same
869 format as double, or for other types with the same format as float,
870 double or long double. The behavior is undefined if the argument
871 does not have a real floating type. The definition may use a
872 conditional expression, so all suffixed versions of FUNC must
873 return the same type (FUNC may include a cast if necessary rather
874 than being a single identifier). */
875 #ifdef __NO_LONG_DOUBLE_MATH
876 # if __HAVE_DISTINCT_FLOAT128
877 # error "Distinct _Float128 without distinct long double not supported."
878 # endif
879 # define __MATH_TG(TG_ARG, FUNC, ARGS) \
880 (sizeof (TG_ARG) == sizeof (float) ? FUNC ## f ARGS : FUNC ARGS)
881 #elif __HAVE_DISTINCT_FLOAT128
882 # if __HAVE_GENERIC_SELECTION
883 # if __HAVE_FLOATN_NOT_TYPEDEF && __HAVE_FLOAT32
884 # define __MATH_TG_F32(FUNC, ARGS) _Float32: FUNC ## f ARGS,
885 # else
886 # define __MATH_TG_F32(FUNC, ARGS)
887 # endif
888 # if __HAVE_FLOATN_NOT_TYPEDEF && __HAVE_FLOAT64X
889 # if __HAVE_FLOAT64X_LONG_DOUBLE
890 # define __MATH_TG_F64X(FUNC, ARGS) _Float64x: FUNC ## l ARGS,
891 # else
892 # define __MATH_TG_F64X(FUNC, ARGS) _Float64x: FUNC ## f128 ARGS,
893 # endif
894 # else
895 # define __MATH_TG_F64X(FUNC, ARGS)
896 # endif
897 # define __MATH_TG(TG_ARG, FUNC, ARGS) \
898 _Generic ((TG_ARG), \
899 float: FUNC ## f ARGS, \
900 __MATH_TG_F32 (FUNC, ARGS) \
901 default: FUNC ARGS, \
902 long double: FUNC ## l ARGS, \
903 __MATH_TG_F64X (FUNC, ARGS) \
904 _Float128: FUNC ## f128 ARGS)
905 # else
906 # if __HAVE_FLOATN_NOT_TYPEDEF
907 # error "Non-typedef _FloatN but no _Generic."
908 # endif
909 # define __MATH_TG(TG_ARG, FUNC, ARGS) \
910 __builtin_choose_expr \
911 (__builtin_types_compatible_p (__typeof (TG_ARG), float), \
912 FUNC ## f ARGS, \
913 __builtin_choose_expr \
914 (__builtin_types_compatible_p (__typeof (TG_ARG), double), \
915 FUNC ARGS, \
916 __builtin_choose_expr \
917 (__builtin_types_compatible_p (__typeof (TG_ARG), long double), \
918 FUNC ## l ARGS, \
919 FUNC ## f128 ARGS)))
920 # endif
921 #else
922 # define __MATH_TG(TG_ARG, FUNC, ARGS) \
923 (sizeof (TG_ARG) == sizeof (float) \
924 ? FUNC ## f ARGS \
925 : sizeof (TG_ARG) == sizeof (double) \
926 ? FUNC ARGS \
927 : FUNC ## l ARGS)
928 #endif
930 /* ISO C99 defines some generic macros which work on any data type. */
931 #ifdef __USE_ISOC99
933 /* All floating-point numbers can be put in one of these categories. */
934 enum
936 FP_NAN =
937 # define FP_NAN 0
938 FP_NAN,
939 FP_INFINITE =
940 # define FP_INFINITE 1
941 FP_INFINITE,
942 FP_ZERO =
943 # define FP_ZERO 2
944 FP_ZERO,
945 FP_SUBNORMAL =
946 # define FP_SUBNORMAL 3
947 FP_SUBNORMAL,
948 FP_NORMAL =
949 # define FP_NORMAL 4
950 FP_NORMAL
953 /* GCC bug 66462 means we cannot use the math builtins with -fsignaling-nan,
954 so disable builtins if this is enabled. When fixed in a newer GCC,
955 the __SUPPORT_SNAN__ check may be skipped for those versions. */
957 /* Return number of classification appropriate for X. */
958 # if ((__GNUC_PREREQ (4,4) && !defined __SUPPORT_SNAN__) \
959 || __glibc_clang_prereq (2,8)) \
960 && (!defined __OPTIMIZE_SIZE__ || defined __cplusplus)
961 /* The check for __cplusplus allows the use of the builtin, even
962 when optimization for size is on. This is provided for
963 libstdc++, only to let its configure test work when it is built
964 with -Os. No further use of this definition of fpclassify is
965 expected in C++ mode, since libstdc++ provides its own version
966 of fpclassify in cmath (which undefines fpclassify). */
967 # define fpclassify(x) __builtin_fpclassify (FP_NAN, FP_INFINITE, \
968 FP_NORMAL, FP_SUBNORMAL, FP_ZERO, x)
969 # else
970 # define fpclassify(x) __MATH_TG ((x), __fpclassify, (x))
971 # endif
973 /* Return nonzero value if sign of X is negative. */
974 # if __GNUC_PREREQ (6,0) || __glibc_clang_prereq (3,3)
975 # define signbit(x) __builtin_signbit (x)
976 # elif defined __cplusplus
977 /* In C++ mode, __MATH_TG cannot be used, because it relies on
978 __builtin_types_compatible_p, which is a C-only builtin.
979 The check for __cplusplus allows the use of the builtin instead of
980 __MATH_TG. This is provided for libstdc++, only to let its configure
981 test work. No further use of this definition of signbit is expected
982 in C++ mode, since libstdc++ provides its own version of signbit
983 in cmath (which undefines signbit). */
984 # define signbit(x) __builtin_signbitl (x)
985 # elif __GNUC_PREREQ (4,0)
986 # define signbit(x) __MATH_TG ((x), __builtin_signbit, (x))
987 # else
988 # define signbit(x) __MATH_TG ((x), __signbit, (x))
989 # endif
991 /* Return nonzero value if X is not +-Inf or NaN. */
992 # if (__GNUC_PREREQ (4,4) && !defined __SUPPORT_SNAN__) \
993 || __glibc_clang_prereq (2,8)
994 # define isfinite(x) __builtin_isfinite (x)
995 # else
996 # define isfinite(x) __MATH_TG ((x), __finite, (x))
997 # endif
999 /* Return nonzero value if X is neither zero, subnormal, Inf, nor NaN. */
1000 # if (__GNUC_PREREQ (4,4) && !defined __SUPPORT_SNAN__) \
1001 || __glibc_clang_prereq (2,8)
1002 # define isnormal(x) __builtin_isnormal (x)
1003 # else
1004 # define isnormal(x) (fpclassify (x) == FP_NORMAL)
1005 # endif
1007 /* Return nonzero value if X is a NaN. We could use `fpclassify' but
1008 we already have this functions `__isnan' and it is faster. */
1009 # if (__GNUC_PREREQ (4,4) && !defined __SUPPORT_SNAN__) \
1010 || __glibc_clang_prereq (2,8)
1011 # define isnan(x) __builtin_isnan (x)
1012 # else
1013 # define isnan(x) __MATH_TG ((x), __isnan, (x))
1014 # endif
1016 /* Return nonzero value if X is positive or negative infinity. */
1017 # if __HAVE_DISTINCT_FLOAT128 && !__GNUC_PREREQ (7,0) \
1018 && !defined __SUPPORT_SNAN__ && !defined __cplusplus
1019 /* Since __builtin_isinf_sign is broken for float128 before GCC 7.0,
1020 use the helper function, __isinff128, with older compilers. This is
1021 only provided for C mode, because in C++ mode, GCC has no support
1022 for __builtin_types_compatible_p (and when in C++ mode, this macro is
1023 not used anyway, because libstdc++ headers undefine it). */
1024 # define isinf(x) \
1025 (__builtin_types_compatible_p (__typeof (x), _Float128) \
1026 ? __isinff128 (x) : __builtin_isinf_sign (x))
1027 # elif (__GNUC_PREREQ (4,4) && !defined __SUPPORT_SNAN__) \
1028 || __glibc_clang_prereq (3,7)
1029 # define isinf(x) __builtin_isinf_sign (x)
1030 # else
1031 # define isinf(x) __MATH_TG ((x), __isinf, (x))
1032 # endif
1034 /* Bitmasks for the math_errhandling macro. */
1035 # define MATH_ERRNO 1 /* errno set by math functions. */
1036 # define MATH_ERREXCEPT 2 /* Exceptions raised by math functions. */
1038 /* By default all math functions support both errno and exception handling
1039 (except for soft floating point implementations which may only support
1040 errno handling). If errno handling is disabled, exceptions are still
1041 supported by GLIBC. Set math_errhandling to 0 with -ffast-math (this is
1042 nonconforming but it is more useful than leaving it undefined). */
1043 # ifdef __FAST_MATH__
1044 # define math_errhandling 0
1045 # elif defined __NO_MATH_ERRNO__
1046 # define math_errhandling (MATH_ERREXCEPT)
1047 # else
1048 # define math_errhandling (MATH_ERRNO | MATH_ERREXCEPT)
1049 # endif
1051 #endif /* Use ISO C99. */
1053 #if __GLIBC_USE (IEC_60559_BFP_EXT_C2X)
1054 # include <bits/iscanonical.h>
1056 /* Return nonzero value if X is a signaling NaN. */
1057 # ifndef __cplusplus
1058 # define issignaling(x) __MATH_TG ((x), __issignaling, (x))
1059 # else
1060 /* In C++ mode, __MATH_TG cannot be used, because it relies on
1061 __builtin_types_compatible_p, which is a C-only builtin. On the
1062 other hand, overloading provides the means to distinguish between
1063 the floating-point types. The overloading resolution will match
1064 the correct parameter (regardless of type qualifiers (i.e.: const
1065 and volatile)). */
1066 extern "C++" {
1067 inline int issignaling (float __val) { return __issignalingf (__val); }
1068 inline int issignaling (double __val) { return __issignaling (__val); }
1069 inline int
1070 issignaling (long double __val)
1072 # ifdef __NO_LONG_DOUBLE_MATH
1073 return __issignaling (__val);
1074 # else
1075 return __issignalingl (__val);
1076 # endif
1078 # if __HAVE_FLOAT128_UNLIKE_LDBL
1079 /* When using an IEEE 128-bit long double, _Float128 is defined as long double
1080 in C++. */
1081 inline int issignaling (_Float128 __val) { return __issignalingf128 (__val); }
1082 # endif
1083 } /* extern C++ */
1084 # endif
1086 /* Return nonzero value if X is subnormal. */
1087 # define issubnormal(x) (fpclassify (x) == FP_SUBNORMAL)
1089 /* Return nonzero value if X is zero. */
1090 # ifndef __cplusplus
1091 # ifdef __SUPPORT_SNAN__
1092 # define iszero(x) (fpclassify (x) == FP_ZERO)
1093 # else
1094 # define iszero(x) (((__typeof (x)) (x)) == 0)
1095 # endif
1096 # else /* __cplusplus */
1097 extern "C++" {
1098 # ifdef __SUPPORT_SNAN__
1099 inline int
1100 iszero (float __val)
1102 return __fpclassifyf (__val) == FP_ZERO;
1104 inline int
1105 iszero (double __val)
1107 return __fpclassify (__val) == FP_ZERO;
1109 inline int
1110 iszero (long double __val)
1112 # ifdef __NO_LONG_DOUBLE_MATH
1113 return __fpclassify (__val) == FP_ZERO;
1114 # else
1115 return __fpclassifyl (__val) == FP_ZERO;
1116 # endif
1118 # if __HAVE_FLOAT128_UNLIKE_LDBL
1119 /* When using an IEEE 128-bit long double, _Float128 is defined as long double
1120 in C++. */
1121 inline int
1122 iszero (_Float128 __val)
1124 return __fpclassifyf128 (__val) == FP_ZERO;
1126 # endif
1127 # else
1128 template <class __T> inline bool
1129 iszero (__T __val)
1131 return __val == 0;
1133 # endif
1134 } /* extern C++ */
1135 # endif /* __cplusplus */
1136 #endif /* Use IEC_60559_BFP_EXT. */
1138 #ifdef __USE_XOPEN
1139 /* X/Open wants another strange constant. */
1140 # define MAXFLOAT 3.40282347e+38F
1141 #endif
1144 /* Some useful constants. */
1145 #if defined __USE_MISC || defined __USE_XOPEN
1146 # define M_E 2.7182818284590452354 /* e */
1147 # define M_LOG2E 1.4426950408889634074 /* log_2 e */
1148 # define M_LOG10E 0.43429448190325182765 /* log_10 e */
1149 # define M_LN2 0.69314718055994530942 /* log_e 2 */
1150 # define M_LN10 2.30258509299404568402 /* log_e 10 */
1151 # define M_PI 3.14159265358979323846 /* pi */
1152 # define M_PI_2 1.57079632679489661923 /* pi/2 */
1153 # define M_PI_4 0.78539816339744830962 /* pi/4 */
1154 # define M_1_PI 0.31830988618379067154 /* 1/pi */
1155 # define M_2_PI 0.63661977236758134308 /* 2/pi */
1156 # define M_2_SQRTPI 1.12837916709551257390 /* 2/sqrt(pi) */
1157 # define M_SQRT2 1.41421356237309504880 /* sqrt(2) */
1158 # define M_SQRT1_2 0.70710678118654752440 /* 1/sqrt(2) */
1159 #endif
1161 /* GNU extension to provide float constants with similar names. */
1162 #ifdef __USE_GNU
1163 # define M_Ef 2.7182818284590452354f /* e */
1164 # define M_LOG2Ef 1.4426950408889634074f /* log_2 e */
1165 # define M_LOG10Ef 0.43429448190325182765f /* log_10 e */
1166 # define M_LN2f 0.69314718055994530942f /* log_e 2 */
1167 # define M_LN10f 2.30258509299404568402f /* log_e 10 */
1168 # define M_PIf 3.14159265358979323846f /* pi */
1169 # define M_PI_2f 1.57079632679489661923f /* pi/2 */
1170 # define M_PI_4f 0.78539816339744830962f /* pi/4 */
1171 # define M_1_PIf 0.31830988618379067154f /* 1/pi */
1172 # define M_2_PIf 0.63661977236758134308f /* 2/pi */
1173 # define M_2_SQRTPIf 1.12837916709551257390f /* 2/sqrt(pi) */
1174 # define M_SQRT2f 1.41421356237309504880f /* sqrt(2) */
1175 # define M_SQRT1_2f 0.70710678118654752440f /* 1/sqrt(2) */
1176 #endif
1178 /* The above constants are not adequate for computation using `long double's.
1179 Therefore we provide as an extension constants with similar names as a
1180 GNU extension. Provide enough digits for the 128-bit IEEE quad. */
1181 #ifdef __USE_GNU
1182 # define M_El 2.718281828459045235360287471352662498L /* e */
1183 # define M_LOG2El 1.442695040888963407359924681001892137L /* log_2 e */
1184 # define M_LOG10El 0.434294481903251827651128918916605082L /* log_10 e */
1185 # define M_LN2l 0.693147180559945309417232121458176568L /* log_e 2 */
1186 # define M_LN10l 2.302585092994045684017991454684364208L /* log_e 10 */
1187 # define M_PIl 3.141592653589793238462643383279502884L /* pi */
1188 # define M_PI_2l 1.570796326794896619231321691639751442L /* pi/2 */
1189 # define M_PI_4l 0.785398163397448309615660845819875721L /* pi/4 */
1190 # define M_1_PIl 0.318309886183790671537767526745028724L /* 1/pi */
1191 # define M_2_PIl 0.636619772367581343075535053490057448L /* 2/pi */
1192 # define M_2_SQRTPIl 1.128379167095512573896158903121545172L /* 2/sqrt(pi) */
1193 # define M_SQRT2l 1.414213562373095048801688724209698079L /* sqrt(2) */
1194 # define M_SQRT1_2l 0.707106781186547524400844362104849039L /* 1/sqrt(2) */
1195 #endif
1197 #if __HAVE_FLOAT16 && defined __USE_GNU
1198 # define M_Ef16 __f16 (2.718281828459045235360287471352662498) /* e */
1199 # define M_LOG2Ef16 __f16 (1.442695040888963407359924681001892137) /* log_2 e */
1200 # define M_LOG10Ef16 __f16 (0.434294481903251827651128918916605082) /* log_10 e */
1201 # define M_LN2f16 __f16 (0.693147180559945309417232121458176568) /* log_e 2 */
1202 # define M_LN10f16 __f16 (2.302585092994045684017991454684364208) /* log_e 10 */
1203 # define M_PIf16 __f16 (3.141592653589793238462643383279502884) /* pi */
1204 # define M_PI_2f16 __f16 (1.570796326794896619231321691639751442) /* pi/2 */
1205 # define M_PI_4f16 __f16 (0.785398163397448309615660845819875721) /* pi/4 */
1206 # define M_1_PIf16 __f16 (0.318309886183790671537767526745028724) /* 1/pi */
1207 # define M_2_PIf16 __f16 (0.636619772367581343075535053490057448) /* 2/pi */
1208 # define M_2_SQRTPIf16 __f16 (1.128379167095512573896158903121545172) /* 2/sqrt(pi) */
1209 # define M_SQRT2f16 __f16 (1.414213562373095048801688724209698079) /* sqrt(2) */
1210 # define M_SQRT1_2f16 __f16 (0.707106781186547524400844362104849039) /* 1/sqrt(2) */
1211 #endif
1213 #if __HAVE_FLOAT32 && defined __USE_GNU
1214 # define M_Ef32 __f32 (2.718281828459045235360287471352662498) /* e */
1215 # define M_LOG2Ef32 __f32 (1.442695040888963407359924681001892137) /* log_2 e */
1216 # define M_LOG10Ef32 __f32 (0.434294481903251827651128918916605082) /* log_10 e */
1217 # define M_LN2f32 __f32 (0.693147180559945309417232121458176568) /* log_e 2 */
1218 # define M_LN10f32 __f32 (2.302585092994045684017991454684364208) /* log_e 10 */
1219 # define M_PIf32 __f32 (3.141592653589793238462643383279502884) /* pi */
1220 # define M_PI_2f32 __f32 (1.570796326794896619231321691639751442) /* pi/2 */
1221 # define M_PI_4f32 __f32 (0.785398163397448309615660845819875721) /* pi/4 */
1222 # define M_1_PIf32 __f32 (0.318309886183790671537767526745028724) /* 1/pi */
1223 # define M_2_PIf32 __f32 (0.636619772367581343075535053490057448) /* 2/pi */
1224 # define M_2_SQRTPIf32 __f32 (1.128379167095512573896158903121545172) /* 2/sqrt(pi) */
1225 # define M_SQRT2f32 __f32 (1.414213562373095048801688724209698079) /* sqrt(2) */
1226 # define M_SQRT1_2f32 __f32 (0.707106781186547524400844362104849039) /* 1/sqrt(2) */
1227 #endif
1229 #if __HAVE_FLOAT64 && defined __USE_GNU
1230 # define M_Ef64 __f64 (2.718281828459045235360287471352662498) /* e */
1231 # define M_LOG2Ef64 __f64 (1.442695040888963407359924681001892137) /* log_2 e */
1232 # define M_LOG10Ef64 __f64 (0.434294481903251827651128918916605082) /* log_10 e */
1233 # define M_LN2f64 __f64 (0.693147180559945309417232121458176568) /* log_e 2 */
1234 # define M_LN10f64 __f64 (2.302585092994045684017991454684364208) /* log_e 10 */
1235 # define M_PIf64 __f64 (3.141592653589793238462643383279502884) /* pi */
1236 # define M_PI_2f64 __f64 (1.570796326794896619231321691639751442) /* pi/2 */
1237 # define M_PI_4f64 __f64 (0.785398163397448309615660845819875721) /* pi/4 */
1238 # define M_1_PIf64 __f64 (0.318309886183790671537767526745028724) /* 1/pi */
1239 # define M_2_PIf64 __f64 (0.636619772367581343075535053490057448) /* 2/pi */
1240 # define M_2_SQRTPIf64 __f64 (1.128379167095512573896158903121545172) /* 2/sqrt(pi) */
1241 # define M_SQRT2f64 __f64 (1.414213562373095048801688724209698079) /* sqrt(2) */
1242 # define M_SQRT1_2f64 __f64 (0.707106781186547524400844362104849039) /* 1/sqrt(2) */
1243 #endif
1245 #if __HAVE_FLOAT128 && defined __USE_GNU
1246 # define M_Ef128 __f128 (2.718281828459045235360287471352662498) /* e */
1247 # define M_LOG2Ef128 __f128 (1.442695040888963407359924681001892137) /* log_2 e */
1248 # define M_LOG10Ef128 __f128 (0.434294481903251827651128918916605082) /* log_10 e */
1249 # define M_LN2f128 __f128 (0.693147180559945309417232121458176568) /* log_e 2 */
1250 # define M_LN10f128 __f128 (2.302585092994045684017991454684364208) /* log_e 10 */
1251 # define M_PIf128 __f128 (3.141592653589793238462643383279502884) /* pi */
1252 # define M_PI_2f128 __f128 (1.570796326794896619231321691639751442) /* pi/2 */
1253 # define M_PI_4f128 __f128 (0.785398163397448309615660845819875721) /* pi/4 */
1254 # define M_1_PIf128 __f128 (0.318309886183790671537767526745028724) /* 1/pi */
1255 # define M_2_PIf128 __f128 (0.636619772367581343075535053490057448) /* 2/pi */
1256 # define M_2_SQRTPIf128 __f128 (1.128379167095512573896158903121545172) /* 2/sqrt(pi) */
1257 # define M_SQRT2f128 __f128 (1.414213562373095048801688724209698079) /* sqrt(2) */
1258 # define M_SQRT1_2f128 __f128 (0.707106781186547524400844362104849039) /* 1/sqrt(2) */
1259 #endif
1261 #if __HAVE_FLOAT32X && defined __USE_GNU
1262 # define M_Ef32x __f32x (2.718281828459045235360287471352662498) /* e */
1263 # define M_LOG2Ef32x __f32x (1.442695040888963407359924681001892137) /* log_2 e */
1264 # define M_LOG10Ef32x __f32x (0.434294481903251827651128918916605082) /* log_10 e */
1265 # define M_LN2f32x __f32x (0.693147180559945309417232121458176568) /* log_e 2 */
1266 # define M_LN10f32x __f32x (2.302585092994045684017991454684364208) /* log_e 10 */
1267 # define M_PIf32x __f32x (3.141592653589793238462643383279502884) /* pi */
1268 # define M_PI_2f32x __f32x (1.570796326794896619231321691639751442) /* pi/2 */
1269 # define M_PI_4f32x __f32x (0.785398163397448309615660845819875721) /* pi/4 */
1270 # define M_1_PIf32x __f32x (0.318309886183790671537767526745028724) /* 1/pi */
1271 # define M_2_PIf32x __f32x (0.636619772367581343075535053490057448) /* 2/pi */
1272 # define M_2_SQRTPIf32x __f32x (1.128379167095512573896158903121545172) /* 2/sqrt(pi) */
1273 # define M_SQRT2f32x __f32x (1.414213562373095048801688724209698079) /* sqrt(2) */
1274 # define M_SQRT1_2f32x __f32x (0.707106781186547524400844362104849039) /* 1/sqrt(2) */
1275 #endif
1277 #if __HAVE_FLOAT64X && defined __USE_GNU
1278 # define M_Ef64x __f64x (2.718281828459045235360287471352662498) /* e */
1279 # define M_LOG2Ef64x __f64x (1.442695040888963407359924681001892137) /* log_2 e */
1280 # define M_LOG10Ef64x __f64x (0.434294481903251827651128918916605082) /* log_10 e */
1281 # define M_LN2f64x __f64x (0.693147180559945309417232121458176568) /* log_e 2 */
1282 # define M_LN10f64x __f64x (2.302585092994045684017991454684364208) /* log_e 10 */
1283 # define M_PIf64x __f64x (3.141592653589793238462643383279502884) /* pi */
1284 # define M_PI_2f64x __f64x (1.570796326794896619231321691639751442) /* pi/2 */
1285 # define M_PI_4f64x __f64x (0.785398163397448309615660845819875721) /* pi/4 */
1286 # define M_1_PIf64x __f64x (0.318309886183790671537767526745028724) /* 1/pi */
1287 # define M_2_PIf64x __f64x (0.636619772367581343075535053490057448) /* 2/pi */
1288 # define M_2_SQRTPIf64x __f64x (1.128379167095512573896158903121545172) /* 2/sqrt(pi) */
1289 # define M_SQRT2f64x __f64x (1.414213562373095048801688724209698079) /* sqrt(2) */
1290 # define M_SQRT1_2f64x __f64x (0.707106781186547524400844362104849039) /* 1/sqrt(2) */
1291 #endif
1293 #if __HAVE_FLOAT128X && defined __USE_GNU
1294 # error "M_* values needed for _Float128x"
1295 #endif
1297 #ifdef __USE_ISOC99
1298 # if __GNUC_PREREQ (3, 1)
1299 /* ISO C99 defines some macros to compare number while taking care for
1300 unordered numbers. Many FPUs provide special instructions to support
1301 these operations. Generic support in GCC for these as builtins went
1302 in 2.97, but not all cpus added their patterns until 3.1. Therefore
1303 we enable the builtins from 3.1 onwards and use a generic implementation
1304 othwerwise. */
1305 # define isgreater(x, y) __builtin_isgreater(x, y)
1306 # define isgreaterequal(x, y) __builtin_isgreaterequal(x, y)
1307 # define isless(x, y) __builtin_isless(x, y)
1308 # define islessequal(x, y) __builtin_islessequal(x, y)
1309 # define islessgreater(x, y) __builtin_islessgreater(x, y)
1310 # define isunordered(x, y) __builtin_isunordered(x, y)
1311 # else
1312 # define isgreater(x, y) \
1313 (__extension__ ({ __typeof__ (x) __x = (x); __typeof__ (y) __y = (y); \
1314 !isunordered (__x, __y) && __x > __y; }))
1315 # define isgreaterequal(x, y) \
1316 (__extension__ ({ __typeof__ (x) __x = (x); __typeof__ (y) __y = (y); \
1317 !isunordered (__x, __y) && __x >= __y; }))
1318 # define isless(x, y) \
1319 (__extension__ ({ __typeof__ (x) __x = (x); __typeof__ (y) __y = (y); \
1320 !isunordered (__x, __y) && __x < __y; }))
1321 # define islessequal(x, y) \
1322 (__extension__ ({ __typeof__ (x) __x = (x); __typeof__ (y) __y = (y); \
1323 !isunordered (__x, __y) && __x <= __y; }))
1324 # define islessgreater(x, y) \
1325 (__extension__ ({ __typeof__ (x) __x = (x); __typeof__ (y) __y = (y); \
1326 !isunordered (__x, __y) && __x != __y; }))
1327 /* isunordered must always check both operands first for signaling NaNs. */
1328 # define isunordered(x, y) \
1329 (__extension__ ({ __typeof__ (x) __u = (x); __typeof__ (y) __v = (y); \
1330 __u != __v && (__u != __u || __v != __v); }))
1331 # endif
1332 #endif
1334 #if __GLIBC_USE (IEC_60559_BFP_EXT_C2X)
1335 /* An expression whose type has the widest of the evaluation formats
1336 of X and Y (which are of floating-point types). */
1337 # if __FLT_EVAL_METHOD__ == 2 || __FLT_EVAL_METHOD__ > 64
1338 # define __MATH_EVAL_FMT2(x, y) ((x) + (y) + 0.0L)
1339 # elif __FLT_EVAL_METHOD__ == 1 || __FLT_EVAL_METHOD__ > 32
1340 # define __MATH_EVAL_FMT2(x, y) ((x) + (y) + 0.0)
1341 # elif __FLT_EVAL_METHOD__ == 0 || __FLT_EVAL_METHOD__ == 32
1342 # define __MATH_EVAL_FMT2(x, y) ((x) + (y) + 0.0f)
1343 # else
1344 # define __MATH_EVAL_FMT2(x, y) ((x) + (y))
1345 # endif
1347 /* Return X == Y but raising "invalid" and setting errno if X or Y is
1348 a NaN. */
1349 # if !defined __cplusplus || (__cplusplus < 201103L && !defined __GNUC__)
1350 # define iseqsig(x, y) \
1351 __MATH_TG (__MATH_EVAL_FMT2 (x, y), __iseqsig, ((x), (y)))
1352 # else
1353 /* In C++ mode, __MATH_TG cannot be used, because it relies on
1354 __builtin_types_compatible_p, which is a C-only builtin. Moreover,
1355 the comparison macros from ISO C take two floating-point arguments,
1356 which need not have the same type. Choosing what underlying function
1357 to call requires evaluating the formats of the arguments, then
1358 selecting which is wider. The macro __MATH_EVAL_FMT2 provides this
1359 information, however, only the type of the macro expansion is
1360 relevant (actually evaluating the expression would be incorrect).
1361 Thus, the type is used as a template parameter for __iseqsig_type,
1362 which calls the appropriate underlying function. */
1363 extern "C++" {
1364 template<typename> struct __iseqsig_type;
1366 template<> struct __iseqsig_type<float>
1368 static int __call (float __x, float __y) throw ()
1370 return __iseqsigf (__x, __y);
1374 template<> struct __iseqsig_type<double>
1376 static int __call (double __x, double __y) throw ()
1378 return __iseqsig (__x, __y);
1382 template<> struct __iseqsig_type<long double>
1384 static int __call (long double __x, long double __y) throw ()
1386 # ifndef __NO_LONG_DOUBLE_MATH
1387 return __iseqsigl (__x, __y);
1388 # else
1389 return __iseqsig (__x, __y);
1390 # endif
1394 # if __HAVE_FLOAT32 && __GNUC_PREREQ (13, 0)
1395 template<> struct __iseqsig_type<_Float32>
1397 static int __call (_Float32 __x, _Float32 __y) throw ()
1399 return __iseqsigf (__x, __y);
1402 # endif
1404 # if __HAVE_FLOAT64 && __GNUC_PREREQ (13, 0)
1405 template<> struct __iseqsig_type<_Float64>
1407 static int __call (_Float64 __x, _Float64 __y) throw ()
1409 return __iseqsig (__x, __y);
1412 # endif
1414 # if __HAVE_FLOAT128_UNLIKE_LDBL || (__HAVE_FLOAT128 && __GNUC_PREREQ (13, 0))
1415 /* When using an IEEE 128-bit long double, _Float128 is defined as long double
1416 in C++. */
1417 template<> struct __iseqsig_type<_Float128>
1419 static int __call (_Float128 __x, _Float128 __y) throw ()
1421 # if __HAVE_FLOAT128_UNLIKE_LDBL
1422 return __iseqsigf128 (__x, __y);
1423 # else
1424 return __iseqsigl (__x, __y);
1425 # endif
1428 # endif
1430 # if __HAVE_FLOAT32X && __GNUC_PREREQ (13, 0)
1431 template<> struct __iseqsig_type<_Float32x>
1433 static int __call (_Float32x __x, _Float32x __y) throw ()
1435 return __iseqsig (__x, __y);
1438 # endif
1440 # if __HAVE_FLOAT64X && __GNUC_PREREQ (13, 0)
1441 template<> struct __iseqsig_type<_Float64x>
1443 static int __call (_Float64x __x, _Float64x __y) throw ()
1445 # if __HAVE_FLOAT64X_LONG_DOUBLE
1446 return __iseqsigl (__x, __y);
1447 # else
1448 return __iseqsigf128 (__x, __y);
1449 # endif
1452 # endif
1454 template<typename _T1, typename _T2>
1455 inline int
1456 iseqsig (_T1 __x, _T2 __y) throw ()
1458 # if __cplusplus >= 201103L
1459 typedef decltype (__MATH_EVAL_FMT2 (__x, __y)) _T3;
1460 # else
1461 typedef __typeof (__MATH_EVAL_FMT2 (__x, __y)) _T3;
1462 # endif
1463 return __iseqsig_type<_T3>::__call (__x, __y);
1466 } /* extern "C++" */
1467 # endif /* __cplusplus */
1469 #endif
1471 __END_DECLS
1474 #endif /* math.h */