]> git.ipfire.org Git - thirdparty/glibc.git/blame - math/math.h
Add build-many-glibcs.py arm-linux-gnueabihf-v7{-disable-multiarch}
[thirdparty/glibc.git] / math / math.h
CommitLineData
f7eac6eb 1/* Declarations for math functions.
bfff8b1b 2 Copyright (C) 1991-2017 Free Software Foundation, Inc.
ba1ffaa1 3 This file is part of the GNU C Library.
28f540f4 4
ba1ffaa1 5 The GNU C Library is free software; you can redistribute it and/or
41bdb6e2
AJ
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.
28f540f4 9
ba1ffaa1
UD
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
41bdb6e2 13 Lesser General Public License for more details.
28f540f4 14
41bdb6e2 15 You should have received a copy of the GNU Lesser General Public
59ba27a6
PE
16 License along with the GNU C Library; if not, see
17 <http://www.gnu.org/licenses/>. */
28f540f4
RM
18
19/*
d1646309 20 * ISO C99 Standard: 7.12 Mathematics <math.h>
28f540f4
RM
21 */
22
23#ifndef _MATH_H
28f540f4 24#define _MATH_H 1
5107cf1d 25
bf91be88
JM
26#define __GLIBC_INTERNAL_STARTING_HEADER_IMPLEMENTATION
27#include <bits/libc-header-start.h>
28f540f4 28
b38042f5
FW
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
28f540f4
RM
34__BEGIN_DECLS
35
423c2b9d
JM
36/* Get definitions of __intmax_t and __uintmax_t. */
37#include <bits/types.h>
38
202d48da
AS
39/* Get machine-dependent vector math functions declarations. */
40#include <bits/math-vector.h>
41
fcee5905
PM
42/* Gather machine dependent type support. */
43#include <bits/floatn.h>
44
a617bd11
ZW
45/* Value returned on overflow. With IEEE 754 floating point, this is
46 +Infinity, otherwise the largest representable positive value. */
a60eca2e
JM
47#if __GNUC_PREREQ (3, 3)
48# define HUGE_VAL (__builtin_huge_val ())
49#else
a617bd11
ZW
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. */
a60eca2e
JM
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
fcee5905 66#if __HAVE_FLOAT128 && __GLIBC_USE (IEC_60559_TYPES_EXT)
a60eca2e 67# define HUGE_VAL_F128 (__builtin_huge_valf128 ())
fcee5905
PM
68#endif
69
a86573f4 70#ifdef __USE_ISOC99
5ef1b213
JM
71/* IEEE positive infinity. */
72# if __GNUC_PREREQ (3, 3)
73# define INFINITY (__builtin_inff ())
74# else
75# define INFINITY HUGE_VALF
76# endif
28f540f4 77
c0c49d60
JM
78/* IEEE Not A Number. */
79# if __GNUC_PREREQ (3, 3)
80# define NAN (__builtin_nanf (""))
81# else
82/* This will raise an "invalid" exception outside static initializers,
83 but is the best that can be done in ISO C while remaining a
84 constant expression. */
85# define NAN (0.0f / 0.0f)
86# endif
a86573f4
RH
87#endif /* __USE_ISOC99 */
88
f82a4bdb
JM
89#if __GLIBC_USE (IEC_60559_BFP_EXT)
90/* Signaling NaN macros, if supported. */
91# if __GNUC_PREREQ (3, 3)
92# define SNANF (__builtin_nansf (""))
93# define SNAN (__builtin_nans (""))
94# define SNANL (__builtin_nansl (""))
95# endif
96#endif
302bb1a3
PM
97#if __HAVE_FLOAT128 && __GLIBC_USE (IEC_60559_TYPES_EXT)
98# define SNANF128 (__builtin_nansf128 (""))
99#endif
f82a4bdb 100
93eb85ce
JM
101/* Get __GLIBC_FLT_EVAL_METHOD. */
102#include <bits/flt-eval-method.h>
103
104#ifdef __USE_ISOC99
105/* Define the following typedefs.
89a12e6f
JM
106
107 float_t floating-point type at least as wide as `float' used
108 to evaluate `float' expressions
109 double_t floating-point type at least as wide as `double' used
110 to evaluate `double' expressions
93eb85ce
JM
111*/
112# if __GLIBC_FLT_EVAL_METHOD == 0 || __GLIBC_FLT_EVAL_METHOD == 16
113typedef float float_t;
114typedef double double_t;
115# elif __GLIBC_FLT_EVAL_METHOD == 1
116typedef double float_t;
117typedef double double_t;
118# elif __GLIBC_FLT_EVAL_METHOD == 2
119typedef long double float_t;
120typedef long double double_t;
121# elif __GLIBC_FLT_EVAL_METHOD == 32
122typedef _Float32 float_t;
123typedef double double_t;
124# elif __GLIBC_FLT_EVAL_METHOD == 33
125typedef _Float32x float_t;
126typedef _Float32x double_t;
127# elif __GLIBC_FLT_EVAL_METHOD == 64
128typedef _Float64 float_t;
129typedef _Float64 double_t;
130# elif __GLIBC_FLT_EVAL_METHOD == 65
131typedef _Float64x float_t;
132typedef _Float64x double_t;
133# elif __GLIBC_FLT_EVAL_METHOD == 128
134typedef _Float128 float_t;
135typedef _Float128 double_t;
136# elif __GLIBC_FLT_EVAL_METHOD == 129
137typedef _Float128x float_t;
138typedef _Float128x double_t;
139# else
140# error "Unknown __GLIBC_FLT_EVAL_METHOD"
141# endif
142#endif
143
55a38f82 144/* Define macros for the return values of ilogb and llogb, based on
b2491db6 145 __FP_LOGB0_IS_MIN and __FP_LOGBNAN_IS_MIN.
f11e220d
JM
146
147 FP_ILOGB0 Expands to a value returned by `ilogb (0.0)'.
148 FP_ILOGBNAN Expands to a value returned by `ilogb (NAN)'.
55a38f82
JM
149 FP_LLOGB0 Expands to a value returned by `llogb (0.0)'.
150 FP_LLOGBNAN Expands to a value returned by `llogb (NAN)'.
f11e220d
JM
151
152*/
153
b2491db6
JM
154#include <bits/fp-logb.h>
155#ifdef __USE_ISOC99
156# if __FP_LOGB0_IS_MIN
157# define FP_ILOGB0 (-2147483647 - 1)
158# else
159# define FP_ILOGB0 (-2147483647)
160# endif
161# if __FP_LOGBNAN_IS_MIN
162# define FP_ILOGBNAN (-2147483647 - 1)
163# else
164# define FP_ILOGBNAN 2147483647
165# endif
166#endif
55a38f82
JM
167#if __GLIBC_USE (IEC_60559_BFP_EXT)
168# if __WORDSIZE == 32
169# define __FP_LONG_MAX 0x7fffffffL
170# else
171# define __FP_LONG_MAX 0x7fffffffffffffffL
172# endif
173# if __FP_LOGB0_IS_MIN
174# define FP_LLOGB0 (-__FP_LONG_MAX - 1)
175# else
176# define FP_LLOGB0 (-__FP_LONG_MAX)
177# endif
178# if __FP_LOGBNAN_IS_MIN
179# define FP_LLOGBNAN (-__FP_LONG_MAX - 1)
180# else
181# define FP_LLOGBNAN __FP_LONG_MAX
182# endif
183#endif
b2491db6 184
93eb85ce
JM
185/* Get the architecture specific values describing the floating-point
186 evaluation. The following symbols will get defined:
89a12e6f
JM
187
188 FP_FAST_FMA
189 FP_FAST_FMAF
190 FP_FAST_FMAL
191 If defined it indicates that the `fma' function
192 generally executes about as fast as a multiply and an add.
193 This macro is defined only iff the `fma' function is
194 implemented directly with a hardware multiply-add instructions.
89a12e6f
JM
195*/
196
f11e220d 197#include <bits/fp-fast.h>
28f540f4 198
423c2b9d
JM
199#if __GLIBC_USE (IEC_60559_BFP_EXT)
200/* Rounding direction macros for fromfp functions. */
201enum
202 {
203 FP_INT_UPWARD =
204# define FP_INT_UPWARD 0
205 FP_INT_UPWARD,
206 FP_INT_DOWNWARD =
207# define FP_INT_DOWNWARD 1
208 FP_INT_DOWNWARD,
209 FP_INT_TOWARDZERO =
210# define FP_INT_TOWARDZERO 2
211 FP_INT_TOWARDZERO,
212 FP_INT_TONEARESTFROMZERO =
213# define FP_INT_TONEARESTFROMZERO 3
214 FP_INT_TONEARESTFROMZERO,
215 FP_INT_TONEAREST =
216# define FP_INT_TONEAREST 4
217 FP_INT_TONEAREST,
218 };
219#endif
220
5107cf1d
UD
221/* The file <bits/mathcalls.h> contains the prototypes for all the
222 actual math functions. These macros are used for those prototypes,
223 so we can easily declare each function as both `name' and `__name',
f7eac6eb
RM
224 and can declare the float versions `namef' and `__namef'. */
225
202d48da
AS
226#define __SIMD_DECL(function) __CONCAT (__DECL_SIMD_, function)
227
228#define __MATHCALL_VEC(function, suffix, args) \
229 __SIMD_DECL (__MATH_PRECNAME (function, suffix)) \
230 __MATHCALL (function, suffix, args)
231
c9a8c526
AS
232#define __MATHDECL_VEC(type, function,suffix, args) \
233 __SIMD_DECL (__MATH_PRECNAME (function, suffix)) \
234 __MATHDECL(type, function,suffix, args)
235
f7eac6eb 236#define __MATHCALL(function,suffix, args) \
377a515b 237 __MATHDECL (_Mdouble_,function,suffix, args)
f7eac6eb
RM
238#define __MATHDECL(type, function,suffix, args) \
239 __MATHDECL_1(type, function,suffix, args); \
377a515b 240 __MATHDECL_1(type, __CONCAT(__,function),suffix, args)
3e5f5557
UD
241#define __MATHCALLX(function,suffix, args, attrib) \
242 __MATHDECLX (_Mdouble_,function,suffix, args, attrib)
243#define __MATHDECLX(type, function,suffix, args, attrib) \
244 __MATHDECL_1(type, function,suffix, args) __attribute__ (attrib); \
245 __MATHDECL_1(type, __CONCAT(__,function),suffix, args) __attribute__ (attrib)
f7eac6eb 246#define __MATHDECL_1(type, function,suffix, args) \
c1422e5b 247 extern type __MATH_PRECNAME(function,suffix) args __THROW
f7eac6eb 248
0ac5ae23 249#define _Mdouble_ double
377a515b 250#define __MATH_PRECNAME(name,r) __CONCAT(name,r)
de20571d 251#define __MATH_DECLARING_DOUBLE 1
fcee5905 252#define __MATH_DECLARING_FLOATN 0
ff80ec42 253#include <bits/mathcalls-helper-functions.h>
5107cf1d 254#include <bits/mathcalls.h>
f7eac6eb
RM
255#undef _Mdouble_
256#undef __MATH_PRECNAME
de20571d 257#undef __MATH_DECLARING_DOUBLE
fcee5905 258#undef __MATH_DECLARING_FLOATN
f7eac6eb 259
acd7f096 260#ifdef __USE_ISOC99
76060ec0 261
999493cb
RM
262
263/* Include the file of declarations again, this time using `float'
f7eac6eb
RM
264 instead of `double' and appending f to each function name. */
265
fe0ec73e
UD
266# ifndef _Mfloat_
267# define _Mfloat_ float
478b92f0 268# endif
0ac5ae23 269# define _Mdouble_ _Mfloat_
7071ad79 270# define __MATH_PRECNAME(name,r) name##f##r
de20571d 271# define __MATH_DECLARING_DOUBLE 0
fcee5905 272# define __MATH_DECLARING_FLOATN 0
ff80ec42 273# include <bits/mathcalls-helper-functions.h>
478b92f0
UD
274# include <bits/mathcalls.h>
275# undef _Mdouble_
276# undef __MATH_PRECNAME
de20571d 277# undef __MATH_DECLARING_DOUBLE
fcee5905 278# undef __MATH_DECLARING_FLOATN
76060ec0 279
7071ad79 280# if !(defined __NO_LONG_DOUBLE_MATH && defined _LIBC) \
dc6fe23b
WN
281 || defined __LDBL_COMPAT \
282 || defined _LIBC_TEST
c6251f03
RM
283# ifdef __LDBL_COMPAT
284
7b943af6 285# ifdef __USE_ISOC99
c6251f03 286extern float __nldbl_nexttowardf (float __x, long double __y)
42247128 287 __THROW __attribute__ ((__const__));
c6251f03
RM
288# ifdef __REDIRECT_NTH
289extern float __REDIRECT_NTH (nexttowardf, (float __x, long double __y),
290 __nldbl_nexttowardf)
291 __attribute__ ((__const__));
292extern double __REDIRECT_NTH (nexttoward, (double __x, long double __y),
293 nextafter) __attribute__ ((__const__));
42247128
RM
294extern long double __REDIRECT_NTH (nexttowardl,
295 (long double __x, long double __y),
296 nextafter) __attribute__ ((__const__));
c6251f03
RM
297# endif
298# endif
299
c6251f03
RM
300# undef __MATHDECL_1
301# define __MATHDECL_2(type, function,suffix, args, alias) \
42247128
RM
302 extern type __REDIRECT_NTH(__MATH_PRECNAME(function,suffix), \
303 args, alias)
c6251f03
RM
304# define __MATHDECL_1(type, function,suffix, args) \
305 __MATHDECL_2(type, function,suffix, args, __CONCAT(function,suffix))
306# endif
307
998832a4
AS
308/* Include the file of declarations again, this time using `long double'
309 instead of `double' and appending l to each function name. */
310
fe0ec73e
UD
311# ifndef _Mlong_double_
312# define _Mlong_double_ long double
313# endif
0ac5ae23 314# define _Mdouble_ _Mlong_double_
7071ad79 315# define __MATH_PRECNAME(name,r) name##l##r
de20571d 316# define __MATH_DECLARING_DOUBLE 0
fcee5905 317# define __MATH_DECLARING_FLOATN 0
0ac5ae23 318# define __MATH_DECLARE_LDOUBLE 1
ff80ec42 319# include <bits/mathcalls-helper-functions.h>
fe0ec73e
UD
320# include <bits/mathcalls.h>
321# undef _Mdouble_
322# undef __MATH_PRECNAME
de20571d 323# undef __MATH_DECLARING_DOUBLE
fcee5905 324# undef __MATH_DECLARING_FLOATN
fe0ec73e 325
7071ad79 326# endif /* !(__NO_LONG_DOUBLE_MATH && _LIBC) || __LDBL_COMPAT */
377a515b 327
acd7f096 328#endif /* Use ISO C99. */
fcee5905
PM
329
330/* Include the file of declarations again, this time using `_Float128'
331 instead of `double' and appending f128 to each function name. */
332
333#if __HAVE_DISTINCT_FLOAT128 || (__HAVE_FLOAT128 && !defined _LIBC)
334# ifndef _Mfloat128_
335# define _Mfloat128_ _Float128
336# endif
337# define _Mdouble_ _Mfloat128_
338# define __MATH_PRECNAME(name,r) name##f128##r
339# define __MATH_DECLARING_DOUBLE 0
340# define __MATH_DECLARING_FLOATN 1
341# if __HAVE_DISTINCT_FLOAT128
342# include <bits/mathcalls-helper-functions.h>
343# endif
344# if __GLIBC_USE (IEC_60559_TYPES_EXT)
345# include <bits/mathcalls.h>
346# endif
347# undef _Mdouble_
348# undef __MATH_PRECNAME
349# undef __MATH_DECLARING_DOUBLE
350# undef __MATH_DECLARING_FLOATN
351#endif /* __HAVE_DISTINCT_FLOAT128. */
352
4cca6b86
UD
353#undef __MATHDECL_1
354#undef __MATHDECL
355#undef __MATHCALL
356
357
00d8bc81 358#if defined __USE_MISC || defined __USE_XOPEN
4cca6b86
UD
359/* This variable is used by `gamma' and `lgamma'. */
360extern int signgam;
361#endif
377a515b
UD
362
363
b4e75104
JM
364/* Depending on the type of TG_ARG, call an appropriately suffixed
365 version of FUNC with arguments (including parentheses) ARGS.
366 Suffixed functions may not exist for long double if it has the same
367 format as double, or for other types with the same format as float,
368 double or long double. The behavior is undefined if the argument
369 does not have a real floating type. The definition may use a
370 conditional expression, so all suffixed versions of FUNC must
371 return the same type (FUNC may include a cast if necessary rather
372 than being a single identifier). */
373#ifdef __NO_LONG_DOUBLE_MATH
374# define __MATH_TG(TG_ARG, FUNC, ARGS) \
375 (sizeof (TG_ARG) == sizeof (float) ? FUNC ## f ARGS : FUNC ARGS)
477bf19a
GG
376#elif __HAVE_DISTINCT_FLOAT128
377# if __HAVE_GENERIC_SELECTION
378# define __MATH_TG(TG_ARG, FUNC, ARGS) \
379 _Generic ((TG_ARG), \
380 float: FUNC ## f ARGS, \
381 default: FUNC ARGS, \
382 long double: FUNC ## l ARGS, \
383 _Float128: FUNC ## f128 ARGS)
384# else
385# define __MATH_TG(TG_ARG, FUNC, ARGS) \
386 __builtin_choose_expr \
387 (__builtin_types_compatible_p (__typeof (TG_ARG), float), \
388 FUNC ## f ARGS, \
389 __builtin_choose_expr \
390 (__builtin_types_compatible_p (__typeof (TG_ARG), double), \
391 FUNC ARGS, \
392 __builtin_choose_expr \
393 (__builtin_types_compatible_p (__typeof (TG_ARG), long double), \
394 FUNC ## l ARGS, \
395 FUNC ## f128 ARGS)))
396# endif
b4e75104
JM
397#else
398# define __MATH_TG(TG_ARG, FUNC, ARGS) \
399 (sizeof (TG_ARG) == sizeof (float) \
400 ? FUNC ## f ARGS \
401 : sizeof (TG_ARG) == sizeof (double) \
402 ? FUNC ARGS \
403 : FUNC ## l ARGS)
404#endif
405
ec751a23 406/* ISO C99 defines some generic macros which work on any data type. */
638bed90 407#ifdef __USE_ISOC99
377a515b
UD
408
409/* All floating-point numbers can be put in one of these categories. */
410enum
411 {
0155d5b2
JM
412 FP_NAN =
413# define FP_NAN 0
414 FP_NAN,
415 FP_INFINITE =
416# define FP_INFINITE 1
417 FP_INFINITE,
418 FP_ZERO =
419# define FP_ZERO 2
420 FP_ZERO,
421 FP_SUBNORMAL =
422# define FP_SUBNORMAL 3
423 FP_SUBNORMAL,
424 FP_NORMAL =
425# define FP_NORMAL 4
426 FP_NORMAL
377a515b
UD
427 };
428
8df4e219
WD
429/* GCC bug 66462 means we cannot use the math builtins with -fsignaling-nan,
430 so disable builtins if this is enabled. When fixed in a newer GCC,
431 the __SUPPORT_SNAN__ check may be skipped for those versions. */
432
377a515b 433/* Return number of classification appropriate for X. */
8df4e219 434# if __GNUC_PREREQ (4,4) && !defined __SUPPORT_SNAN__ \
c5c4a626
GG
435 && (!defined __OPTIMIZE_SIZE__ || defined __cplusplus)
436 /* The check for __cplusplus allows the use of the builtin, even
437 when optimization for size is on. This is provided for
438 libstdc++, only to let its configure test work when it is built
439 with -Os. No further use of this definition of fpclassify is
440 expected in C++ mode, since libstdc++ provides its own version
441 of fpclassify in cmath (which undefines fpclassify). */
8df4e219
WD
442# define fpclassify(x) __builtin_fpclassify (FP_NAN, FP_INFINITE, \
443 FP_NORMAL, FP_SUBNORMAL, FP_ZERO, x)
68337808 444# else
b4e75104 445# define fpclassify(x) __MATH_TG ((x), __fpclassify, (x))
68337808 446# endif
377a515b
UD
447
448/* Return nonzero value if sign of X is negative. */
fcee5905
PM
449# if __GNUC_PREREQ (6,0)
450# define signbit(x) __builtin_signbit (x)
451# elif __GNUC_PREREQ (4,0)
b4e75104 452# define signbit(x) __MATH_TG ((x), __builtin_signbit, (x))
68337808 453# else
b4e75104 454# define signbit(x) __MATH_TG ((x), __signbit, (x))
68337808 455# endif
377a515b
UD
456
457/* Return nonzero value if X is not +-Inf or NaN. */
8df4e219
WD
458# if __GNUC_PREREQ (4,4) && !defined __SUPPORT_SNAN__
459# define isfinite(x) __builtin_isfinite (x)
68337808 460# else
b4e75104 461# define isfinite(x) __MATH_TG ((x), __finite, (x))
68337808 462# endif
377a515b
UD
463
464/* Return nonzero value if X is neither zero, subnormal, Inf, nor NaN. */
8df4e219
WD
465# if __GNUC_PREREQ (4,4) && !defined __SUPPORT_SNAN__
466# define isnormal(x) __builtin_isnormal (x)
467# else
468# define isnormal(x) (fpclassify (x) == FP_NORMAL)
469# endif
377a515b
UD
470
471/* Return nonzero value if X is a NaN. We could use `fpclassify' but
472 we already have this functions `__isnan' and it is faster. */
8df4e219
WD
473# if __GNUC_PREREQ (4,4) && !defined __SUPPORT_SNAN__
474# define isnan(x) __builtin_isnan (x)
68337808 475# else
b4e75104 476# define isnan(x) __MATH_TG ((x), __isnan, (x))
68337808 477# endif
28f540f4 478
0e012e87 479/* Return nonzero value if X is positive or negative infinity. */
fcee5905 480# if __HAVE_DISTINCT_FLOAT128 && !__GNUC_PREREQ (7,0) \
47a67213
GG
481 && !defined __SUPPORT_SNAN__ && !defined __cplusplus
482 /* Since __builtin_isinf_sign is broken for float128 before GCC 7.0,
483 use the helper function, __isinff128, with older compilers. This is
484 only provided for C mode, because in C++ mode, GCC has no support
485 for __builtin_types_compatible_p (and when in C++ mode, this macro is
486 not used anyway, because libstdc++ headers undefine it). */
fcee5905
PM
487# define isinf(x) \
488 (__builtin_types_compatible_p (__typeof (x), _Float128) \
489 ? __isinff128 (x) : __builtin_isinf_sign (x))
490# elif __GNUC_PREREQ (4,4) && !defined __SUPPORT_SNAN__
8df4e219 491# define isinf(x) __builtin_isinf_sign (x)
68337808 492# else
b4e75104 493# define isinf(x) __MATH_TG ((x), __isinf, (x))
68337808 494# endif
bfce746a 495
12b64309
UD
496/* Bitmasks for the math_errhandling macro. */
497# define MATH_ERRNO 1 /* errno set by math functions. */
498# define MATH_ERREXCEPT 2 /* Exceptions raised by math functions. */
499
7b943af6
UD
500/* By default all functions support both errno and exception handling.
501 In gcc's fast math mode and if inline functions are defined this
502 might not be true. */
503# ifndef __FAST_MATH__
504# define math_errhandling (MATH_ERRNO | MATH_ERREXCEPT)
505# endif
506
ec751a23 507#endif /* Use ISO C99. */
377a515b 508
bf91be88 509#if __GLIBC_USE (IEC_60559_BFP_EXT)
29cb9293
JM
510# include <bits/iscanonical.h>
511
57267616 512/* Return nonzero value if X is a signaling NaN. */
a16e8bc0
GG
513# ifndef __cplusplus
514# define issignaling(x) __MATH_TG ((x), __issignaling, (x))
515# else
516 /* In C++ mode, __MATH_TG cannot be used, because it relies on
517 __builtin_types_compatible_p, which is a C-only builtin. On the
518 other hand, overloading provides the means to distinguish between
519 the floating-point types. The overloading resolution will match
520 the correct parameter (regardless of type qualifiers (i.e.: const
aa0235df 521 and volatile)). */
a16e8bc0
GG
522extern "C++" {
523inline int issignaling (float __val) { return __issignalingf (__val); }
524inline int issignaling (double __val) { return __issignaling (__val); }
3d7b66f6
GG
525inline int
526issignaling (long double __val)
527{
528# ifdef __NO_LONG_DOUBLE_MATH
529 return __issignaling (__val);
530# else
531 return __issignalingl (__val);
532# endif
533}
a16e8bc0
GG
534# if __HAVE_DISTINCT_FLOAT128
535inline int issignaling (_Float128 __val) { return __issignalingf128 (__val); }
536# endif
537} /* extern C++ */
538# endif
d942e95c
JM
539
540/* Return nonzero value if X is subnormal. */
541# define issubnormal(x) (fpclassify (x) == FP_SUBNORMAL)
bb8081f5
JM
542
543/* Return nonzero value if X is zero. */
b3918c44
FW
544# ifndef __cplusplus
545# ifdef __SUPPORT_SNAN__
546# define iszero(x) (fpclassify (x) == FP_ZERO)
547# else
548# define iszero(x) (((__typeof (x)) (x)) == 0)
549# endif
550# else /* __cplusplus */
e37208ce 551extern "C++" {
42496114
GG
552# ifdef __SUPPORT_SNAN__
553inline int
554iszero (float __val)
555{
556 return __fpclassifyf (__val) == FP_ZERO;
557}
558inline int
559iszero (double __val)
560{
561 return __fpclassify (__val) == FP_ZERO;
562}
563inline int
564iszero (long double __val)
565{
566# ifdef __NO_LONG_DOUBLE_MATH
567 return __fpclassify (__val) == FP_ZERO;
568# else
569 return __fpclassifyl (__val) == FP_ZERO;
570# endif
571}
572# if __HAVE_DISTINCT_FLOAT128
573inline int
574iszero (_Float128 __val)
575{
576 return __fpclassifyf128 (__val) == FP_ZERO;
577}
578# endif
579# else
b3918c44
FW
580template <class __T> inline bool
581iszero (__T __val)
582{
b3918c44 583 return __val == 0;
b3918c44 584}
42496114 585# endif
e37208ce 586} /* extern C++ */
b3918c44 587# endif /* __cplusplus */
bf91be88 588#endif /* Use IEC_60559_BFP_EXT. */
57267616 589
813378e9 590#ifdef __USE_XOPEN
377a515b 591/* X/Open wants another strange constant. */
813378e9
JM
592# define MAXFLOAT 3.40282347e+38F
593#endif
28f540f4 594
28f540f4 595
28f540f4 596/* Some useful constants. */
498afc54 597#if defined __USE_MISC || defined __USE_XOPEN
0a614877
UD
598# define M_E 2.7182818284590452354 /* e */
599# define M_LOG2E 1.4426950408889634074 /* log_2 e */
600# define M_LOG10E 0.43429448190325182765 /* log_10 e */
601# define M_LN2 0.69314718055994530942 /* log_e 2 */
602# define M_LN10 2.30258509299404568402 /* log_e 10 */
603# define M_PI 3.14159265358979323846 /* pi */
604# define M_PI_2 1.57079632679489661923 /* pi/2 */
605# define M_PI_4 0.78539816339744830962 /* pi/4 */
606# define M_1_PI 0.31830988618379067154 /* 1/pi */
607# define M_2_PI 0.63661977236758134308 /* 2/pi */
608# define M_2_SQRTPI 1.12837916709551257390 /* 2/sqrt(pi) */
609# define M_SQRT2 1.41421356237309504880 /* sqrt(2) */
610# define M_SQRT1_2 0.70710678118654752440 /* 1/sqrt(2) */
714a562f
UD
611#endif
612
0a614877
UD
613/* The above constants are not adequate for computation using `long double's.
614 Therefore we provide as an extension constants with similar names as a
9a24f906 615 GNU extension. Provide enough digits for the 128-bit IEEE quad. */
0a614877 616#ifdef __USE_GNU
2d10d547
JM
617# define M_El 2.718281828459045235360287471352662498L /* e */
618# define M_LOG2El 1.442695040888963407359924681001892137L /* log_2 e */
619# define M_LOG10El 0.434294481903251827651128918916605082L /* log_10 e */
620# define M_LN2l 0.693147180559945309417232121458176568L /* log_e 2 */
621# define M_LN10l 2.302585092994045684017991454684364208L /* log_e 10 */
622# define M_PIl 3.141592653589793238462643383279502884L /* pi */
623# define M_PI_2l 1.570796326794896619231321691639751442L /* pi/2 */
624# define M_PI_4l 0.785398163397448309615660845819875721L /* pi/4 */
625# define M_1_PIl 0.318309886183790671537767526745028724L /* 1/pi */
626# define M_2_PIl 0.636619772367581343075535053490057448L /* 2/pi */
627# define M_2_SQRTPIl 1.128379167095512573896158903121545172L /* 2/sqrt(pi) */
628# define M_SQRT2l 1.414213562373095048801688724209698079L /* sqrt(2) */
629# define M_SQRT1_2l 0.707106781186547524400844362104849039L /* 1/sqrt(2) */
0a614877 630#endif
710f7bab 631
fcee5905
PM
632#if __HAVE_FLOAT128 && defined __USE_GNU
633# define M_Ef128 __f128 (2.718281828459045235360287471352662498) /* e */
634# define M_LOG2Ef128 __f128 (1.442695040888963407359924681001892137) /* log_2 e */
635# define M_LOG10Ef128 __f128 (0.434294481903251827651128918916605082) /* log_10 e */
636# define M_LN2f128 __f128 (0.693147180559945309417232121458176568) /* log_e 2 */
637# define M_LN10f128 __f128 (2.302585092994045684017991454684364208) /* log_e 10 */
638# define M_PIf128 __f128 (3.141592653589793238462643383279502884) /* pi */
639# define M_PI_2f128 __f128 (1.570796326794896619231321691639751442) /* pi/2 */
640# define M_PI_4f128 __f128 (0.785398163397448309615660845819875721) /* pi/4 */
641# define M_1_PIf128 __f128 (0.318309886183790671537767526745028724) /* 1/pi */
642# define M_2_PIf128 __f128 (0.636619772367581343075535053490057448) /* 2/pi */
643# define M_2_SQRTPIf128 __f128 (1.128379167095512573896158903121545172) /* 2/sqrt(pi) */
644# define M_SQRT2f128 __f128 (1.414213562373095048801688724209698079) /* sqrt(2) */
645# define M_SQRT1_2f128 __f128 (0.707106781186547524400844362104849039) /* 1/sqrt(2) */
646#endif
28f540f4 647
00bc5db0
UD
648/* When compiling in strict ISO C compatible mode we must not use the
649 inline functions since they, among other things, do not set the
650 `errno' variable correctly. */
651#if defined __STRICT_ANSI__ && !defined __NO_MATH_INLINES
652# define __NO_MATH_INLINES 1
653#endif
654
1e6d0723
WD
655#ifdef __USE_ISOC99
656# if __GNUC_PREREQ (3, 1)
f4c024d1
UD
657/* ISO C99 defines some macros to compare number while taking care for
658 unordered numbers. Many FPUs provide special instructions to support
659 these operations. Generic support in GCC for these as builtins went
1e6d0723
WD
660 in 2.97, but not all cpus added their patterns until 3.1. Therefore
661 we enable the builtins from 3.1 onwards and use a generic implementation
662 othwerwise. */
663# define isgreater(x, y) __builtin_isgreater(x, y)
664# define isgreaterequal(x, y) __builtin_isgreaterequal(x, y)
665# define isless(x, y) __builtin_isless(x, y)
666# define islessequal(x, y) __builtin_islessequal(x, y)
667# define islessgreater(x, y) __builtin_islessgreater(x, y)
668# define isunordered(x, y) __builtin_isunordered(x, y)
669# else
670# define isgreater(x, y) \
671 (__extension__ ({ __typeof__ (x) __x = (x); __typeof__ (y) __y = (y); \
672 !isunordered (__x, __y) && __x > __y; }))
673# define isgreaterequal(x, y) \
674 (__extension__ ({ __typeof__ (x) __x = (x); __typeof__ (y) __y = (y); \
675 !isunordered (__x, __y) && __x >= __y; }))
676# define isless(x, y) \
677 (__extension__ ({ __typeof__ (x) __x = (x); __typeof__ (y) __y = (y); \
678 !isunordered (__x, __y) && __x < __y; }))
679# define islessequal(x, y) \
680 (__extension__ ({ __typeof__ (x) __x = (x); __typeof__ (y) __y = (y); \
681 !isunordered (__x, __y) && __x <= __y; }))
682# define islessgreater(x, y) \
683 (__extension__ ({ __typeof__ (x) __x = (x); __typeof__ (y) __y = (y); \
684 !isunordered (__x, __y) && __x != __y; }))
685/* isunordered must always check both operands first for signaling NaNs. */
686# define isunordered(x, y) \
687 (__extension__ ({ __typeof__ (x) __u = (x); __typeof__ (y) __v = (y); \
688 __u != __v && (__u != __u || __v != __v); }))
689# endif
f4c024d1
UD
690#endif
691
4d585333 692/* Get machine-dependent inline versions (if there are any). */
0c6cee5d 693#ifdef __USE_EXTERN_INLINES
478b92f0 694# include <bits/mathinline.h>
4d585333
RM
695#endif
696
0ac5ae23
UD
697/* Define special entry points to use when the compiler got told to
698 only expect finite results. */
699#if defined __FINITE_MATH_ONLY__ && __FINITE_MATH_ONLY__ > 0
f264cca5
GG
700
701/* Include bits/math-finite.h for double. */
702# define _Mdouble_ double
703# define __MATH_DECLARING_DOUBLE 1
33d523d7 704# define __MATH_DECLARING_FLOATN 0
7daada03
JM
705# define __REDIRFROM_X(function, reentrant) \
706 function ## reentrant
707# define __REDIRTO_X(function, reentrant) \
708 __ ## function ## reentrant ## _finite
0ac5ae23 709# include <bits/math-finite.h>
f264cca5
GG
710# undef _Mdouble_
711# undef __MATH_DECLARING_DOUBLE
33d523d7 712# undef __MATH_DECLARING_FLOATN
7daada03
JM
713# undef __REDIRFROM_X
714# undef __REDIRTO_X
f264cca5
GG
715
716/* When __USE_ISOC99 is defined, include math-finite for float and
717 long double, as well. */
718# ifdef __USE_ISOC99
719
720/* Include bits/math-finite.h for float. */
721# define _Mdouble_ float
722# define __MATH_DECLARING_DOUBLE 0
33d523d7 723# define __MATH_DECLARING_FLOATN 0
7daada03
JM
724# define __REDIRFROM_X(function, reentrant) \
725 function ## f ## reentrant
726# define __REDIRTO_X(function, reentrant) \
727 __ ## function ## f ## reentrant ## _finite
f264cca5
GG
728# include <bits/math-finite.h>
729# undef _Mdouble_
730# undef __MATH_DECLARING_DOUBLE
33d523d7 731# undef __MATH_DECLARING_FLOATN
7daada03
JM
732# undef __REDIRFROM_X
733# undef __REDIRTO_X
f264cca5
GG
734
735/* Include bits/math-finite.h for long double. */
1361e98d 736# ifdef __MATH_DECLARE_LDOUBLE
f264cca5
GG
737# define _Mdouble_ long double
738# define __MATH_DECLARING_DOUBLE 0
33d523d7 739# define __MATH_DECLARING_FLOATN 0
7daada03
JM
740# define __REDIRFROM_X(function, reentrant) \
741 function ## l ## reentrant
23761119 742# ifdef __NO_LONG_DOUBLE_MATH
7daada03
JM
743# define __REDIRTO_X(function, reentrant) \
744 __ ## function ## reentrant ## _finite
23761119 745# else
7daada03
JM
746# define __REDIRTO_X(function, reentrant) \
747 __ ## function ## l ## reentrant ## _finite
23761119 748# endif
f264cca5
GG
749# include <bits/math-finite.h>
750# undef _Mdouble_
751# undef __MATH_DECLARING_DOUBLE
33d523d7 752# undef __MATH_DECLARING_FLOATN
7daada03
JM
753# undef __REDIRFROM_X
754# undef __REDIRTO_X
f264cca5
GG
755# endif
756
757# endif /* __USE_ISOC99. */
33d523d7
GG
758
759/* Include bits/math-finite.h for float128. */
760# if (__HAVE_DISTINCT_FLOAT128 || (__HAVE_FLOAT128 && !defined _LIBC)) \
761 && __GLIBC_USE (IEC_60559_TYPES_EXT)
762# define _Mdouble_ _Float128
763# define __MATH_DECLARING_DOUBLE 0
33d523d7 764# define __MATH_DECLARING_FLOATN 1
7daada03
JM
765# define __REDIRFROM_X(function, reentrant) \
766 function ## f128 ## reentrant
23761119 767# if __HAVE_DISTINCT_FLOAT128
7daada03
JM
768# define __REDIRTO_X(function, reentrant) \
769 __ ## function ## f128 ## reentrant ## _finite
23761119 770# else
7daada03
JM
771# define __REDIRTO_X(function, reentrant) \
772 __ ## function ## l ## reentrant ## _finite
23761119 773# endif
33d523d7
GG
774# include <bits/math-finite.h>
775# undef _Mdouble_
776# undef __MATH_DECLARING_DOUBLE
33d523d7 777# undef __MATH_DECLARING_FLOATN
7daada03
JM
778# undef __REDIRFROM_X
779# undef __REDIRTO_X
33d523d7 780# endif
f264cca5 781#endif /* __FINITE_MATH_ONLY__ > 0. */
0ac5ae23 782
1e7c8fcc 783#if __GLIBC_USE (IEC_60559_BFP_EXT)
b4e75104
JM
784/* An expression whose type has the widest of the evaluation formats
785 of X and Y (which are of floating-point types). */
786# if __FLT_EVAL_METHOD__ == 2 || __FLT_EVAL_METHOD__ > 64
787# define __MATH_EVAL_FMT2(x, y) ((x) + (y) + 0.0L)
788# elif __FLT_EVAL_METHOD__ == 1 || __FLT_EVAL_METHOD__ > 32
789# define __MATH_EVAL_FMT2(x, y) ((x) + (y) + 0.0)
1e7c8fcc 790# else
b4e75104 791# define __MATH_EVAL_FMT2(x, y) ((x) + (y))
1e7c8fcc 792# endif
b4e75104
JM
793
794/* Return X == Y but raising "invalid" and setting errno if X or Y is
795 a NaN. */
796# define iseqsig(x, y) \
797 __MATH_TG (__MATH_EVAL_FMT2 (x, y), __iseqsig, ((x), (y)))
1e7c8fcc
JM
798#endif
799
4d585333
RM
800__END_DECLS
801
802
28f540f4 803#endif /* math.h */