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