1/* Declarations for math functions.
2 Copyright (C) 1991-2018 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <http://www.gnu.org/licenses/>. */
18
19/*
20 * ISO C99 Standard: 7.12 Mathematics <math.h>
21 */
22
23#ifndef _MATH_H
24#define _MATH_H 1
25
26#define __GLIBC_INTERNAL_STARTING_HEADER_IMPLEMENTATION
27#include <bits/libc-header-start.h>
28
29#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)
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)
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)
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
487#if defined __USE_MISC || defined __USE_XOPEN
488/* This variable is used by `gamma' and `lgamma'. */
489extern int signgam;
490#endif
491
492#if (__HAVE_DISTINCT_FLOAT16 \
493 || __HAVE_DISTINCT_FLOAT32 \
494 || __HAVE_DISTINCT_FLOAT64 \
495 || __HAVE_DISTINCT_FLOAT32X \
496 || __HAVE_DISTINCT_FLOAT64X \
497 || __HAVE_DISTINCT_FLOAT128X)
498# error "Unsupported _FloatN or _FloatNx types for <math.h>."
499#endif
500
501/* Depending on the type of TG_ARG, call an appropriately suffixed
502 version of FUNC with arguments (including parentheses) ARGS.
503 Suffixed functions may not exist for long double if it has the same
504 format as double, or for other types with the same format as float,
505 double or long double. The behavior is undefined if the argument
506 does not have a real floating type. The definition may use a
507 conditional expression, so all suffixed versions of FUNC must
508 return the same type (FUNC may include a cast if necessary rather
509 than being a single identifier). */
510#ifdef __NO_LONG_DOUBLE_MATH
511# if __HAVE_DISTINCT_FLOAT128
512# error "Distinct _Float128 without distinct long double not supported."
513# endif
514# define __MATH_TG(TG_ARG, FUNC, ARGS) \
515 (sizeof (TG_ARG) == sizeof (float) ? FUNC ## f ARGS : FUNC ARGS)
516#elif __HAVE_DISTINCT_FLOAT128
517# if __HAVE_GENERIC_SELECTION
518# if __HAVE_FLOATN_NOT_TYPEDEF && __HAVE_FLOAT32
519# define __MATH_TG_F32(FUNC, ARGS) _Float32: FUNC ## f ARGS,
520# else
521# define __MATH_TG_F32(FUNC, ARGS)
522# endif
523# if __HAVE_FLOATN_NOT_TYPEDEF && __HAVE_FLOAT64X
524# if __HAVE_FLOAT64X_LONG_DOUBLE
525# define __MATH_TG_F64X(FUNC, ARGS) _Float64x: FUNC ## l ARGS,
526# else
527# define __MATH_TG_F64X(FUNC, ARGS) _Float64x: FUNC ## f128 ARGS,
528# endif
529# else
530# define __MATH_TG_F64X(FUNC, ARGS)
531# endif
532# define __MATH_TG(TG_ARG, FUNC, ARGS) \
533 _Generic ((TG_ARG), \
534 float: FUNC ## f ARGS, \
535 __MATH_TG_F32 (FUNC, ARGS) \
536 default: FUNC ARGS, \
537 long double: FUNC ## l ARGS, \
538 __MATH_TG_F64X (FUNC, ARGS) \
539 _Float128: FUNC ## f128 ARGS)
540# else
541# if __HAVE_FLOATN_NOT_TYPEDEF
542# error "Non-typedef _FloatN but no _Generic."
543# endif
544# define __MATH_TG(TG_ARG, FUNC, ARGS) \
545 __builtin_choose_expr \
546 (__builtin_types_compatible_p (__typeof (TG_ARG), float), \
547 FUNC ## f ARGS, \
548 __builtin_choose_expr \
549 (__builtin_types_compatible_p (__typeof (TG_ARG), double), \
550 FUNC ARGS, \
551 __builtin_choose_expr \
552 (__builtin_types_compatible_p (__typeof (TG_ARG), long double), \
553 FUNC ## l ARGS, \
554 FUNC ## f128 ARGS)))
555# endif
556#else
557# define __MATH_TG(TG_ARG, FUNC, ARGS) \
558 (sizeof (TG_ARG) == sizeof (float) \
559 ? FUNC ## f ARGS \
560 : sizeof (TG_ARG) == sizeof (double) \
561 ? FUNC ARGS \
562 : FUNC ## l ARGS)
563#endif
564
565/* ISO C99 defines some generic macros which work on any data type. */
566#ifdef __USE_ISOC99
567
568/* All floating-point numbers can be put in one of these categories. */
569enum
570 {
571 FP_NAN =
572# define FP_NAN 0
573 FP_NAN,
574 FP_INFINITE =
575# define FP_INFINITE 1
576 FP_INFINITE,
577 FP_ZERO =
578# define FP_ZERO 2
579 FP_ZERO,
580 FP_SUBNORMAL =
581# define FP_SUBNORMAL 3
582 FP_SUBNORMAL,
583 FP_NORMAL =
584# define FP_NORMAL 4
585 FP_NORMAL
586 };
587
588/* GCC bug 66462 means we cannot use the math builtins with -fsignaling-nan,
589 so disable builtins if this is enabled. When fixed in a newer GCC,
590 the __SUPPORT_SNAN__ check may be skipped for those versions. */
591
592/* Return number of classification appropriate for X. */
593# if __GNUC_PREREQ (4,4) && !defined __SUPPORT_SNAN__ \
594 && (!defined __OPTIMIZE_SIZE__ || defined __cplusplus)
595 /* The check for __cplusplus allows the use of the builtin, even
596 when optimization for size is on. This is provided for
597 libstdc++, only to let its configure test work when it is built
598 with -Os. No further use of this definition of fpclassify is
599 expected in C++ mode, since libstdc++ provides its own version
600 of fpclassify in cmath (which undefines fpclassify). */
601# define fpclassify(x) __builtin_fpclassify (FP_NAN, FP_INFINITE, \
602 FP_NORMAL, FP_SUBNORMAL, FP_ZERO, x)
603# else
604# define fpclassify(x) __MATH_TG ((x), __fpclassify, (x))
605# endif
606
607/* Return nonzero value if sign of X is negative. */
608# if __GNUC_PREREQ (6,0)
609# define signbit(x) __builtin_signbit (x)
610# elif defined __cplusplus
611 /* In C++ mode, __MATH_TG cannot be used, because it relies on
612 __builtin_types_compatible_p, which is a C-only builtin.
613 The check for __cplusplus allows the use of the builtin instead of
614 __MATH_TG. This is provided for libstdc++, only to let its configure
615 test work. No further use of this definition of signbit is expected
616 in C++ mode, since libstdc++ provides its own version of signbit
617 in cmath (which undefines signbit). */
618# define signbit(x) __builtin_signbitl (x)
619# elif __GNUC_PREREQ (4,0)
620# define signbit(x) __MATH_TG ((x), __builtin_signbit, (x))
621# else
622# define signbit(x) __MATH_TG ((x), __signbit, (x))
623# endif
624
625/* Return nonzero value if X is not +-Inf or NaN. */
626# if __GNUC_PREREQ (4,4) && !defined __SUPPORT_SNAN__
627# define isfinite(x) __builtin_isfinite (x)
628# else
629# define isfinite(x) __MATH_TG ((x), __finite, (x))
630# endif
631
632/* Return nonzero value if X is neither zero, subnormal, Inf, nor NaN. */
633# if __GNUC_PREREQ (4,4) && !defined __SUPPORT_SNAN__
634# define isnormal(x) __builtin_isnormal (x)
635# else
636# define isnormal(x) (fpclassify (x) == FP_NORMAL)
637# endif
638
639/* Return nonzero value if X is a NaN. We could use `fpclassify' but
640 we already have this functions `__isnan' and it is faster. */
641# if __GNUC_PREREQ (4,4) && !defined __SUPPORT_SNAN__
642# define isnan(x) __builtin_isnan (x)
643# else
644# define isnan(x) __MATH_TG ((x), __isnan, (x))
645# endif
646
647/* Return nonzero value if X is positive or negative infinity. */
648# if __HAVE_DISTINCT_FLOAT128 && !__GNUC_PREREQ (7,0) \
649 && !defined __SUPPORT_SNAN__ && !defined __cplusplus
650 /* Since __builtin_isinf_sign is broken for float128 before GCC 7.0,
651 use the helper function, __isinff128, with older compilers. This is
652 only provided for C mode, because in C++ mode, GCC has no support
653 for __builtin_types_compatible_p (and when in C++ mode, this macro is
654 not used anyway, because libstdc++ headers undefine it). */
655# define isinf(x) \
656 (__builtin_types_compatible_p (__typeof (x), _Float128) \
657 ? __isinff128 (x) : __builtin_isinf_sign (x))
658# elif __GNUC_PREREQ (4,4) && !defined __SUPPORT_SNAN__
659# define isinf(x) __builtin_isinf_sign (x)
660# else
661# define isinf(x) __MATH_TG ((x), __isinf, (x))
662# endif
663
664/* Bitmasks for the math_errhandling macro. */
665# define MATH_ERRNO 1 /* errno set by math functions. */
666# define MATH_ERREXCEPT 2 /* Exceptions raised by math functions. */
667
668/* By default all math functions support both errno and exception handling
669 (except for soft floating point implementations which may only support
670 errno handling). If errno handling is disabled, exceptions are still
671 supported by GLIBC. Set math_errhandling to 0 with -ffast-math (this is
672 nonconforming but it is more useful than leaving it undefined). */
673# ifdef __FAST_MATH__
674# define math_errhandling 0
675# elif defined __NO_MATH_ERRNO__
676# define math_errhandling (MATH_ERREXCEPT)
677# else
678# define math_errhandling (MATH_ERRNO | MATH_ERREXCEPT)
679# endif
680
681#endif /* Use ISO C99. */
682
683#if __GLIBC_USE (IEC_60559_BFP_EXT)
684# include <bits/iscanonical.h>
685
686/* Return nonzero value if X is a signaling NaN. */
687# ifndef __cplusplus
688# define issignaling(x) __MATH_TG ((x), __issignaling, (x))
689# else
690 /* In C++ mode, __MATH_TG cannot be used, because it relies on
691 __builtin_types_compatible_p, which is a C-only builtin. On the
692 other hand, overloading provides the means to distinguish between
693 the floating-point types. The overloading resolution will match
694 the correct parameter (regardless of type qualifiers (i.e.: const
695 and volatile)). */
696extern "C++" {
697inline int issignaling (float __val) { return __issignalingf (__val); }
698inline int issignaling (double __val) { return __issignaling (__val); }
699inline int
700issignaling (long double __val)
701{
702# ifdef __NO_LONG_DOUBLE_MATH
703 return __issignaling (__val);
704# else
705 return __issignalingl (__val);
706# endif
707}
708# if __HAVE_DISTINCT_FLOAT128
709inline int issignaling (_Float128 __val) { return __issignalingf128 (__val); }
710# endif
711} /* extern C++ */
712# endif
713
714/* Return nonzero value if X is subnormal. */
715# define issubnormal(x) (fpclassify (x) == FP_SUBNORMAL)
716
717/* Return nonzero value if X is zero. */
718# ifndef __cplusplus
719# ifdef __SUPPORT_SNAN__
720# define iszero(x) (fpclassify (x) == FP_ZERO)
721# else
722# define iszero(x) (((__typeof (x)) (x)) == 0)
723# endif
724# else /* __cplusplus */
725extern "C++" {
726# ifdef __SUPPORT_SNAN__
727inline int
728iszero (float __val)
729{
730 return __fpclassifyf (__val) == FP_ZERO;
731}
732inline int
733iszero (double __val)
734{
735 return __fpclassify (__val) == FP_ZERO;
736}
737inline int
738iszero (long double __val)
739{
740# ifdef __NO_LONG_DOUBLE_MATH
741 return __fpclassify (__val) == FP_ZERO;
742# else
743 return __fpclassifyl (__val) == FP_ZERO;
744# endif
745}
746# if __HAVE_DISTINCT_FLOAT128
747inline int
748iszero (_Float128 __val)
749{
750 return __fpclassifyf128 (__val) == FP_ZERO;
751}
752# endif
753# else
754template <class __T> inline bool
755iszero (__T __val)
756{
757 return __val == 0;
758}
759# endif
760} /* extern C++ */
761# endif /* __cplusplus */
762#endif /* Use IEC_60559_BFP_EXT. */
763
764#ifdef __USE_XOPEN
765/* X/Open wants another strange constant. */
766# define MAXFLOAT 3.40282347e+38F
767#endif
768
769
770/* Some useful constants. */
771#if defined __USE_MISC || defined __USE_XOPEN
772# define M_E 2.7182818284590452354 /* e */
773# define M_LOG2E 1.4426950408889634074 /* log_2 e */
774# define M_LOG10E 0.43429448190325182765 /* log_10 e */
775# define M_LN2 0.69314718055994530942 /* log_e 2 */
776# define M_LN10 2.30258509299404568402 /* log_e 10 */
777# define M_PI 3.14159265358979323846 /* pi */
778# define M_PI_2 1.57079632679489661923 /* pi/2 */
779# define M_PI_4 0.78539816339744830962 /* pi/4 */
780# define M_1_PI 0.31830988618379067154 /* 1/pi */
781# define M_2_PI 0.63661977236758134308 /* 2/pi */
782# define M_2_SQRTPI 1.12837916709551257390 /* 2/sqrt(pi) */
783# define M_SQRT2 1.41421356237309504880 /* sqrt(2) */
784# define M_SQRT1_2 0.70710678118654752440 /* 1/sqrt(2) */
785#endif
786
787/* The above constants are not adequate for computation using `long double's.
788 Therefore we provide as an extension constants with similar names as a
789 GNU extension. Provide enough digits for the 128-bit IEEE quad. */
790#ifdef __USE_GNU
791# define M_El 2.718281828459045235360287471352662498L /* e */
792# define M_LOG2El 1.442695040888963407359924681001892137L /* log_2 e */
793# define M_LOG10El 0.434294481903251827651128918916605082L /* log_10 e */
794# define M_LN2l 0.693147180559945309417232121458176568L /* log_e 2 */
795# define M_LN10l 2.302585092994045684017991454684364208L /* log_e 10 */
796# define M_PIl 3.141592653589793238462643383279502884L /* pi */
797# define M_PI_2l 1.570796326794896619231321691639751442L /* pi/2 */
798# define M_PI_4l 0.785398163397448309615660845819875721L /* pi/4 */
799# define M_1_PIl 0.318309886183790671537767526745028724L /* 1/pi */
800# define M_2_PIl 0.636619772367581343075535053490057448L /* 2/pi */
801# define M_2_SQRTPIl 1.128379167095512573896158903121545172L /* 2/sqrt(pi) */
802# define M_SQRT2l 1.414213562373095048801688724209698079L /* sqrt(2) */
803# define M_SQRT1_2l 0.707106781186547524400844362104849039L /* 1/sqrt(2) */
804#endif
805
806#if __HAVE_FLOAT16 && defined __USE_GNU
807# define M_Ef16 __f16 (2.718281828459045235360287471352662498) /* e */
808# define M_LOG2Ef16 __f16 (1.442695040888963407359924681001892137) /* log_2 e */
809# define M_LOG10Ef16 __f16 (0.434294481903251827651128918916605082) /* log_10 e */
810# define M_LN2f16 __f16 (0.693147180559945309417232121458176568) /* log_e 2 */
811# define M_LN10f16 __f16 (2.302585092994045684017991454684364208) /* log_e 10 */
812# define M_PIf16 __f16 (3.141592653589793238462643383279502884) /* pi */
813# define M_PI_2f16 __f16 (1.570796326794896619231321691639751442) /* pi/2 */
814# define M_PI_4f16 __f16 (0.785398163397448309615660845819875721) /* pi/4 */
815# define M_1_PIf16 __f16 (0.318309886183790671537767526745028724) /* 1/pi */
816# define M_2_PIf16 __f16 (0.636619772367581343075535053490057448) /* 2/pi */
817# define M_2_SQRTPIf16 __f16 (1.128379167095512573896158903121545172) /* 2/sqrt(pi) */
818# define M_SQRT2f16 __f16 (1.414213562373095048801688724209698079) /* sqrt(2) */
819# define M_SQRT1_2f16 __f16 (0.707106781186547524400844362104849039) /* 1/sqrt(2) */
820#endif
821
822#if __HAVE_FLOAT32 && defined __USE_GNU
823# define M_Ef32 __f32 (2.718281828459045235360287471352662498) /* e */
824# define M_LOG2Ef32 __f32 (1.442695040888963407359924681001892137) /* log_2 e */
825# define M_LOG10Ef32 __f32 (0.434294481903251827651128918916605082) /* log_10 e */
826# define M_LN2f32 __f32 (0.693147180559945309417232121458176568) /* log_e 2 */
827# define M_LN10f32 __f32 (2.302585092994045684017991454684364208) /* log_e 10 */
828# define M_PIf32 __f32 (3.141592653589793238462643383279502884) /* pi */
829# define M_PI_2f32 __f32 (1.570796326794896619231321691639751442) /* pi/2 */
830# define M_PI_4f32 __f32 (0.785398163397448309615660845819875721) /* pi/4 */
831# define M_1_PIf32 __f32 (0.318309886183790671537767526745028724) /* 1/pi */
832# define M_2_PIf32 __f32 (0.636619772367581343075535053490057448) /* 2/pi */
833# define M_2_SQRTPIf32 __f32 (1.128379167095512573896158903121545172) /* 2/sqrt(pi) */
834# define M_SQRT2f32 __f32 (1.414213562373095048801688724209698079) /* sqrt(2) */
835# define M_SQRT1_2f32 __f32 (0.707106781186547524400844362104849039) /* 1/sqrt(2) */
836#endif
837
838#if __HAVE_FLOAT64 && defined __USE_GNU
839# define M_Ef64 __f64 (2.718281828459045235360287471352662498) /* e */
840# define M_LOG2Ef64 __f64 (1.442695040888963407359924681001892137) /* log_2 e */
841# define M_LOG10Ef64 __f64 (0.434294481903251827651128918916605082) /* log_10 e */
842# define M_LN2f64 __f64 (0.693147180559945309417232121458176568) /* log_e 2 */
843# define M_LN10f64 __f64 (2.302585092994045684017991454684364208) /* log_e 10 */
844# define M_PIf64 __f64 (3.141592653589793238462643383279502884) /* pi */
845# define M_PI_2f64 __f64 (1.570796326794896619231321691639751442) /* pi/2 */
846# define M_PI_4f64 __f64 (0.785398163397448309615660845819875721) /* pi/4 */
847# define M_1_PIf64 __f64 (0.318309886183790671537767526745028724) /* 1/pi */
848# define M_2_PIf64 __f64 (0.636619772367581343075535053490057448) /* 2/pi */
849# define M_2_SQRTPIf64 __f64 (1.128379167095512573896158903121545172) /* 2/sqrt(pi) */
850# define M_SQRT2f64 __f64 (1.414213562373095048801688724209698079) /* sqrt(2) */
851# define M_SQRT1_2f64 __f64 (0.707106781186547524400844362104849039) /* 1/sqrt(2) */
852#endif
853
854#if __HAVE_FLOAT128 && defined __USE_GNU
855# define M_Ef128 __f128 (2.718281828459045235360287471352662498) /* e */
856# define M_LOG2Ef128 __f128 (1.442695040888963407359924681001892137) /* log_2 e */
857# define M_LOG10Ef128 __f128 (0.434294481903251827651128918916605082) /* log_10 e */
858# define M_LN2f128 __f128 (0.693147180559945309417232121458176568) /* log_e 2 */
859# define M_LN10f128 __f128 (2.302585092994045684017991454684364208) /* log_e 10 */
860# define M_PIf128 __f128 (3.141592653589793238462643383279502884) /* pi */
861# define M_PI_2f128 __f128 (1.570796326794896619231321691639751442) /* pi/2 */
862# define M_PI_4f128 __f128 (0.785398163397448309615660845819875721) /* pi/4 */
863# define M_1_PIf128 __f128 (0.318309886183790671537767526745028724) /* 1/pi */
864# define M_2_PIf128 __f128 (0.636619772367581343075535053490057448) /* 2/pi */
865# define M_2_SQRTPIf128 __f128 (1.128379167095512573896158903121545172) /* 2/sqrt(pi) */
866# define M_SQRT2f128 __f128 (1.414213562373095048801688724209698079) /* sqrt(2) */
867# define M_SQRT1_2f128 __f128 (0.707106781186547524400844362104849039) /* 1/sqrt(2) */
868#endif
869
870#if __HAVE_FLOAT32X && defined __USE_GNU
871# define M_Ef32x __f32x (2.718281828459045235360287471352662498) /* e */
872# define M_LOG2Ef32x __f32x (1.442695040888963407359924681001892137) /* log_2 e */
873# define M_LOG10Ef32x __f32x (0.434294481903251827651128918916605082) /* log_10 e */
874# define M_LN2f32x __f32x (0.693147180559945309417232121458176568) /* log_e 2 */
875# define M_LN10f32x __f32x (2.302585092994045684017991454684364208) /* log_e 10 */
876# define M_PIf32x __f32x (3.141592653589793238462643383279502884) /* pi */
877# define M_PI_2f32x __f32x (1.570796326794896619231321691639751442) /* pi/2 */
878# define M_PI_4f32x __f32x (0.785398163397448309615660845819875721) /* pi/4 */
879# define M_1_PIf32x __f32x (0.318309886183790671537767526745028724) /* 1/pi */
880# define M_2_PIf32x __f32x (0.636619772367581343075535053490057448) /* 2/pi */
881# define M_2_SQRTPIf32x __f32x (1.128379167095512573896158903121545172) /* 2/sqrt(pi) */
882# define M_SQRT2f32x __f32x (1.414213562373095048801688724209698079) /* sqrt(2) */
883# define M_SQRT1_2f32x __f32x (0.707106781186547524400844362104849039) /* 1/sqrt(2) */
884#endif
885
886#if __HAVE_FLOAT64X && defined __USE_GNU
887# define M_Ef64x __f64x (2.718281828459045235360287471352662498) /* e */
888# define M_LOG2Ef64x __f64x (1.442695040888963407359924681001892137) /* log_2 e */
889# define M_LOG10Ef64x __f64x (0.434294481903251827651128918916605082) /* log_10 e */
890# define M_LN2f64x __f64x (0.693147180559945309417232121458176568) /* log_e 2 */
891# define M_LN10f64x __f64x (2.302585092994045684017991454684364208) /* log_e 10 */
892# define M_PIf64x __f64x (3.141592653589793238462643383279502884) /* pi */
893# define M_PI_2f64x __f64x (1.570796326794896619231321691639751442) /* pi/2 */
894# define M_PI_4f64x __f64x (0.785398163397448309615660845819875721) /* pi/4 */
895# define M_1_PIf64x __f64x (0.318309886183790671537767526745028724) /* 1/pi */
896# define M_2_PIf64x __f64x (0.636619772367581343075535053490057448) /* 2/pi */
897# define M_2_SQRTPIf64x __f64x (1.128379167095512573896158903121545172) /* 2/sqrt(pi) */
898# define M_SQRT2f64x __f64x (1.414213562373095048801688724209698079) /* sqrt(2) */
899# define M_SQRT1_2f64x __f64x (0.707106781186547524400844362104849039) /* 1/sqrt(2) */
900#endif
901
902#if __HAVE_FLOAT128X && defined __USE_GNU
903# error "M_* values needed for _Float128x"
904#endif
905
906/* When compiling in strict ISO C compatible mode we must not use the
907 inline functions since they, among other things, do not set the
908 `errno' variable correctly. */
909#if defined __STRICT_ANSI__ && !defined __NO_MATH_INLINES
910# define __NO_MATH_INLINES 1
911#endif
912
913#ifdef __USE_ISOC99
914# if __GNUC_PREREQ (3, 1)
915/* ISO C99 defines some macros to compare number while taking care for
916 unordered numbers. Many FPUs provide special instructions to support
917 these operations. Generic support in GCC for these as builtins went
918 in 2.97, but not all cpus added their patterns until 3.1. Therefore
919 we enable the builtins from 3.1 onwards and use a generic implementation
920 othwerwise. */
921# define isgreater(x, y) __builtin_isgreater(x, y)
922# define isgreaterequal(x, y) __builtin_isgreaterequal(x, y)
923# define isless(x, y) __builtin_isless(x, y)
924# define islessequal(x, y) __builtin_islessequal(x, y)
925# define islessgreater(x, y) __builtin_islessgreater(x, y)
926# define isunordered(x, y) __builtin_isunordered(x, y)
927# else
928# define isgreater(x, y) \
929 (__extension__ ({ __typeof__ (x) __x = (x); __typeof__ (y) __y = (y); \
930 !isunordered (__x, __y) && __x > __y; }))
931# define isgreaterequal(x, y) \
932 (__extension__ ({ __typeof__ (x) __x = (x); __typeof__ (y) __y = (y); \
933 !isunordered (__x, __y) && __x >= __y; }))
934# define isless(x, y) \
935 (__extension__ ({ __typeof__ (x) __x = (x); __typeof__ (y) __y = (y); \
936 !isunordered (__x, __y) && __x < __y; }))
937# define islessequal(x, y) \
938 (__extension__ ({ __typeof__ (x) __x = (x); __typeof__ (y) __y = (y); \
939 !isunordered (__x, __y) && __x <= __y; }))
940# define islessgreater(x, y) \
941 (__extension__ ({ __typeof__ (x) __x = (x); __typeof__ (y) __y = (y); \
942 !isunordered (__x, __y) && __x != __y; }))
943/* isunordered must always check both operands first for signaling NaNs. */
944# define isunordered(x, y) \
945 (__extension__ ({ __typeof__ (x) __u = (x); __typeof__ (y) __v = (y); \
946 __u != __v && (__u != __u || __v != __v); }))
947# endif
948#endif
949
950/* Get machine-dependent inline versions (if there are any). */
951#ifdef __USE_EXTERN_INLINES
952# include <bits/mathinline.h>
953#endif
954
955/* Define special entry points to use when the compiler got told to
956 only expect finite results. */
957#if defined __FINITE_MATH_ONLY__ && __FINITE_MATH_ONLY__ > 0
958
959/* Include bits/math-finite.h for double. */
960# define _Mdouble_ double
961# define __MATH_DECLARING_DOUBLE 1
962# define __MATH_DECLARING_FLOATN 0
963# define __REDIRFROM_X(function, reentrant) \
964 function ## reentrant
965# define __REDIRTO_X(function, reentrant) \
966 __ ## function ## reentrant ## _finite
967# include <bits/math-finite.h>
968# undef _Mdouble_
969# undef __MATH_DECLARING_DOUBLE
970# undef __MATH_DECLARING_FLOATN
971# undef __REDIRFROM_X
972# undef __REDIRTO_X
973
974/* When __USE_ISOC99 is defined, include math-finite for float and
975 long double, as well. */
976# ifdef __USE_ISOC99
977
978/* Include bits/math-finite.h for float. */
979# define _Mdouble_ float
980# define __MATH_DECLARING_DOUBLE 0
981# define __MATH_DECLARING_FLOATN 0
982# define __REDIRFROM_X(function, reentrant) \
983 function ## f ## reentrant
984# define __REDIRTO_X(function, reentrant) \
985 __ ## function ## f ## reentrant ## _finite
986# include <bits/math-finite.h>
987# undef _Mdouble_
988# undef __MATH_DECLARING_DOUBLE
989# undef __MATH_DECLARING_FLOATN
990# undef __REDIRFROM_X
991# undef __REDIRTO_X
992
993/* Include bits/math-finite.h for long double. */
994# ifdef __MATH_DECLARE_LDOUBLE
995# define _Mdouble_ long double
996# define __MATH_DECLARING_DOUBLE 0
997# define __MATH_DECLARING_FLOATN 0
998# define __REDIRFROM_X(function, reentrant) \
999 function ## l ## reentrant
1000# ifdef __NO_LONG_DOUBLE_MATH
1001# define __REDIRTO_X(function, reentrant) \
1002 __ ## function ## reentrant ## _finite
1003# else
1004# define __REDIRTO_X(function, reentrant) \
1005 __ ## function ## l ## reentrant ## _finite
1006# endif
1007# include <bits/math-finite.h>
1008# undef _Mdouble_
1009# undef __MATH_DECLARING_DOUBLE
1010# undef __MATH_DECLARING_FLOATN
1011# undef __REDIRFROM_X
1012# undef __REDIRTO_X
1013# endif
1014
1015# endif /* __USE_ISOC99. */
1016
1017/* Include bits/math-finite.h for _FloatN and _FloatNx. */
1018
1019# if (__HAVE_DISTINCT_FLOAT16 || (__HAVE_FLOAT16 && !defined _LIBC)) \
1020 && __GLIBC_USE (IEC_60559_TYPES_EXT)
1021# define _Mdouble_ _Float16
1022# define __MATH_DECLARING_DOUBLE 0
1023# define __MATH_DECLARING_FLOATN 1
1024# define __REDIRFROM_X(function, reentrant) \
1025 function ## f16 ## reentrant
1026# if __HAVE_DISTINCT_FLOAT16
1027# define __REDIRTO_X(function, reentrant) \
1028 __ ## function ## f16 ## reentrant ## _finite
1029# else
1030# error "non-disinct _Float16"
1031# endif
1032# include <bits/math-finite.h>
1033# undef _Mdouble_
1034# undef __MATH_DECLARING_DOUBLE
1035# undef __MATH_DECLARING_FLOATN
1036# undef __REDIRFROM_X
1037# undef __REDIRTO_X
1038# endif
1039
1040# if (__HAVE_DISTINCT_FLOAT32 || (__HAVE_FLOAT32 && !defined _LIBC)) \
1041 && __GLIBC_USE (IEC_60559_TYPES_EXT)
1042# define _Mdouble_ _Float32
1043# define __MATH_DECLARING_DOUBLE 0
1044# define __MATH_DECLARING_FLOATN 1
1045# define __REDIRFROM_X(function, reentrant) \
1046 function ## f32 ## reentrant
1047# if __HAVE_DISTINCT_FLOAT32
1048# define __REDIRTO_X(function, reentrant) \
1049 __ ## function ## f32 ## reentrant ## _finite
1050# else
1051# define __REDIRTO_X(function, reentrant) \
1052 __ ## function ## f ## reentrant ## _finite
1053# endif
1054# include <bits/math-finite.h>
1055# undef _Mdouble_
1056# undef __MATH_DECLARING_DOUBLE
1057# undef __MATH_DECLARING_FLOATN
1058# undef __REDIRFROM_X
1059# undef __REDIRTO_X
1060# endif
1061
1062# if (__HAVE_DISTINCT_FLOAT64 || (__HAVE_FLOAT64 && !defined _LIBC)) \
1063 && __GLIBC_USE (IEC_60559_TYPES_EXT)
1064# define _Mdouble_ _Float64
1065# define __MATH_DECLARING_DOUBLE 0
1066# define __MATH_DECLARING_FLOATN 1
1067# define __REDIRFROM_X(function, reentrant) \
1068 function ## f64 ## reentrant
1069# if __HAVE_DISTINCT_FLOAT64
1070# define __REDIRTO_X(function, reentrant) \
1071 __ ## function ## f64 ## reentrant ## _finite
1072# else
1073# define __REDIRTO_X(function, reentrant) \
1074 __ ## function ## reentrant ## _finite
1075# endif
1076# include <bits/math-finite.h>
1077# undef _Mdouble_
1078# undef __MATH_DECLARING_DOUBLE
1079# undef __MATH_DECLARING_FLOATN
1080# undef __REDIRFROM_X
1081# undef __REDIRTO_X
1082# endif
1083
1084# if (__HAVE_DISTINCT_FLOAT128 || (__HAVE_FLOAT128 && !defined _LIBC)) \
1085 && __GLIBC_USE (IEC_60559_TYPES_EXT)
1086# define _Mdouble_ _Float128
1087# define __MATH_DECLARING_DOUBLE 0
1088# define __MATH_DECLARING_FLOATN 1
1089# define __REDIRFROM_X(function, reentrant) \
1090 function ## f128 ## reentrant
1091# if __HAVE_DISTINCT_FLOAT128
1092# define __REDIRTO_X(function, reentrant) \
1093 __ ## function ## f128 ## reentrant ## _finite
1094# else
1095# define __REDIRTO_X(function, reentrant) \
1096 __ ## function ## l ## reentrant ## _finite
1097# endif
1098# include <bits/math-finite.h>
1099# undef _Mdouble_
1100# undef __MATH_DECLARING_DOUBLE
1101# undef __MATH_DECLARING_FLOATN
1102# undef __REDIRFROM_X
1103# undef __REDIRTO_X
1104# endif
1105
1106# if (__HAVE_DISTINCT_FLOAT32X || (__HAVE_FLOAT32X && !defined _LIBC)) \
1107 && __GLIBC_USE (IEC_60559_TYPES_EXT)
1108# define _Mdouble_ _Float32x
1109# define __MATH_DECLARING_DOUBLE 0
1110# define __MATH_DECLARING_FLOATN 1
1111# define __REDIRFROM_X(function, reentrant) \
1112 function ## f32x ## reentrant
1113# if __HAVE_DISTINCT_FLOAT32X
1114# define __REDIRTO_X(function, reentrant) \
1115 __ ## function ## f32x ## reentrant ## _finite
1116# else
1117# define __REDIRTO_X(function, reentrant) \
1118 __ ## function ## reentrant ## _finite
1119# endif
1120# include <bits/math-finite.h>
1121# undef _Mdouble_
1122# undef __MATH_DECLARING_DOUBLE
1123# undef __MATH_DECLARING_FLOATN
1124# undef __REDIRFROM_X
1125# undef __REDIRTO_X
1126# endif
1127
1128# if (__HAVE_DISTINCT_FLOAT64X || (__HAVE_FLOAT64X && !defined _LIBC)) \
1129 && __GLIBC_USE (IEC_60559_TYPES_EXT)
1130# define _Mdouble_ _Float64x
1131# define __MATH_DECLARING_DOUBLE 0
1132# define __MATH_DECLARING_FLOATN 1
1133# define __REDIRFROM_X(function, reentrant) \
1134 function ## f64x ## reentrant
1135# if __HAVE_DISTINCT_FLOAT64X
1136# define __REDIRTO_X(function, reentrant) \
1137 __ ## function ## f64x ## reentrant ## _finite
1138# elif __HAVE_FLOAT64X_LONG_DOUBLE
1139# define __REDIRTO_X(function, reentrant) \
1140 __ ## function ## l ## reentrant ## _finite
1141# else
1142# define __REDIRTO_X(function, reentrant) \
1143 __ ## function ## f128 ## reentrant ## _finite
1144# endif
1145# include <bits/math-finite.h>
1146# undef _Mdouble_
1147# undef __MATH_DECLARING_DOUBLE
1148# undef __MATH_DECLARING_FLOATN
1149# undef __REDIRFROM_X
1150# undef __REDIRTO_X
1151# endif
1152
1153# if (__HAVE_DISTINCT_FLOAT128X || (__HAVE_FLOAT128X && !defined _LIBC)) \
1154 && __GLIBC_USE (IEC_60559_TYPES_EXT)
1155# define _Mdouble_ _Float128x
1156# define __MATH_DECLARING_DOUBLE 0
1157# define __MATH_DECLARING_FLOATN 1
1158# define __REDIRFROM_X(function, reentrant) \
1159 function ## f128x ## reentrant
1160# if __HAVE_DISTINCT_FLOAT128X
1161# define __REDIRTO_X(function, reentrant) \
1162 __ ## function ## f128x ## reentrant ## _finite
1163# else
1164# error "non-disinct _Float128x"
1165# endif
1166# include <bits/math-finite.h>
1167# undef _Mdouble_
1168# undef __MATH_DECLARING_DOUBLE
1169# undef __MATH_DECLARING_FLOATN
1170# undef __REDIRFROM_X
1171# undef __REDIRTO_X
1172# endif
1173
1174#endif /* __FINITE_MATH_ONLY__ > 0. */
1175
1176#if __GLIBC_USE (IEC_60559_BFP_EXT)
1177/* An expression whose type has the widest of the evaluation formats
1178 of X and Y (which are of floating-point types). */
1179# if __FLT_EVAL_METHOD__ == 2 || __FLT_EVAL_METHOD__ > 64
1180# define __MATH_EVAL_FMT2(x, y) ((x) + (y) + 0.0L)
1181# elif __FLT_EVAL_METHOD__ == 1 || __FLT_EVAL_METHOD__ > 32
1182# define __MATH_EVAL_FMT2(x, y) ((x) + (y) + 0.0)
1183# elif __FLT_EVAL_METHOD__ == 0 || __FLT_EVAL_METHOD__ == 32
1184# define __MATH_EVAL_FMT2(x, y) ((x) + (y) + 0.0f)
1185# else
1186# define __MATH_EVAL_FMT2(x, y) ((x) + (y))
1187# endif
1188
1189/* Return X == Y but raising "invalid" and setting errno if X or Y is
1190 a NaN. */
1191# if !defined __cplusplus || (__cplusplus < 201103L && !defined __GNUC__)
1192# define iseqsig(x, y) \
1193 __MATH_TG (__MATH_EVAL_FMT2 (x, y), __iseqsig, ((x), (y)))
1194# else
1195/* In C++ mode, __MATH_TG cannot be used, because it relies on
1196 __builtin_types_compatible_p, which is a C-only builtin. Moreover,
1197 the comparison macros from ISO C take two floating-point arguments,
1198 which need not have the same type. Choosing what underlying function
1199 to call requires evaluating the formats of the arguments, then
1200 selecting which is wider. The macro __MATH_EVAL_FMT2 provides this
1201 information, however, only the type of the macro expansion is
1202 relevant (actually evaluating the expression would be incorrect).
1203 Thus, the type is used as a template parameter for __iseqsig_type,
1204 which calls the appropriate underlying function. */
1205extern "C++" {
1206template<typename> struct __iseqsig_type;
1207
1208template<> struct __iseqsig_type<float>
1209{
1210 static int __call (float __x, float __y) throw ()
1211 {
1212 return __iseqsigf (__x, __y);
1213 }
1214};
1215
1216template<> struct __iseqsig_type<double>
1217{
1218 static int __call (double __x, double __y) throw ()
1219 {
1220 return __iseqsig (__x, __y);
1221 }
1222};
1223
1224template<> struct __iseqsig_type<long double>
1225{
1226 static int __call (double __x, double __y) throw ()
1227 {
1228# ifndef __NO_LONG_DOUBLE_MATH
1229 return __iseqsigl (__x, __y);
1230# else
1231 return __iseqsig (__x, __y);
1232# endif
1233 }
1234};
1235
1236# if __HAVE_DISTINCT_FLOAT128
1237template<> struct __iseqsig_type<_Float128>
1238{
1239 static int __call (_Float128 __x, _Float128 __y) throw ()
1240 {
1241 return __iseqsigf128 (__x, __y);
1242 }
1243};
1244# endif
1245
1246template<typename _T1, typename _T2>
1247inline int
1248iseqsig (_T1 __x, _T2 __y) throw ()
1249{
1250# if __cplusplus >= 201103L
1251 typedef decltype (__MATH_EVAL_FMT2 (__x, __y)) _T3;
1252# else
1253 typedef __typeof (__MATH_EVAL_FMT2 (__x, __y)) _T3;
1254# endif
1255 return __iseqsig_type<_T3>::__call (__x, __y);
1256}
1257
1258} /* extern "C++" */
1259# endif /* __cplusplus */
1260
1261#endif
1262
1263__END_DECLS
1264
1265
1266#endif /* math.h */
1267