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