]> git.ipfire.org Git - thirdparty/glibc.git/blame - math/math.h
add myself as contact for "br" locale
[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)
386e1c26
RN
451# elif defined __cplusplus
452 /* In C++ mode, __MATH_TG cannot be used, because it relies on
453 __builtin_types_compatible_p, which is a C-only builtin.
454 The check for __cplusplus allows the use of the builtin instead of
455 __MATH_TG. This is provided for libstdc++, only to let its configure
456 test work. No further use of this definition of signbit is expected
457 in C++ mode, since libstdc++ provides its own version of signbit
458 in cmath (which undefines signbit). */
459# define signbit(x) __builtin_signbitl (x)
fcee5905 460# elif __GNUC_PREREQ (4,0)
b4e75104 461# define signbit(x) __MATH_TG ((x), __builtin_signbit, (x))
68337808 462# else
b4e75104 463# define signbit(x) __MATH_TG ((x), __signbit, (x))
68337808 464# endif
377a515b
UD
465
466/* Return nonzero value if X is not +-Inf or NaN. */
8df4e219
WD
467# if __GNUC_PREREQ (4,4) && !defined __SUPPORT_SNAN__
468# define isfinite(x) __builtin_isfinite (x)
68337808 469# else
b4e75104 470# define isfinite(x) __MATH_TG ((x), __finite, (x))
68337808 471# endif
377a515b
UD
472
473/* Return nonzero value if X is neither zero, subnormal, Inf, nor NaN. */
8df4e219
WD
474# if __GNUC_PREREQ (4,4) && !defined __SUPPORT_SNAN__
475# define isnormal(x) __builtin_isnormal (x)
476# else
477# define isnormal(x) (fpclassify (x) == FP_NORMAL)
478# endif
377a515b
UD
479
480/* Return nonzero value if X is a NaN. We could use `fpclassify' but
481 we already have this functions `__isnan' and it is faster. */
8df4e219
WD
482# if __GNUC_PREREQ (4,4) && !defined __SUPPORT_SNAN__
483# define isnan(x) __builtin_isnan (x)
68337808 484# else
b4e75104 485# define isnan(x) __MATH_TG ((x), __isnan, (x))
68337808 486# endif
28f540f4 487
0e012e87 488/* Return nonzero value if X is positive or negative infinity. */
fcee5905 489# if __HAVE_DISTINCT_FLOAT128 && !__GNUC_PREREQ (7,0) \
47a67213
GG
490 && !defined __SUPPORT_SNAN__ && !defined __cplusplus
491 /* Since __builtin_isinf_sign is broken for float128 before GCC 7.0,
492 use the helper function, __isinff128, with older compilers. This is
493 only provided for C mode, because in C++ mode, GCC has no support
494 for __builtin_types_compatible_p (and when in C++ mode, this macro is
495 not used anyway, because libstdc++ headers undefine it). */
fcee5905
PM
496# define isinf(x) \
497 (__builtin_types_compatible_p (__typeof (x), _Float128) \
498 ? __isinff128 (x) : __builtin_isinf_sign (x))
499# elif __GNUC_PREREQ (4,4) && !defined __SUPPORT_SNAN__
8df4e219 500# define isinf(x) __builtin_isinf_sign (x)
68337808 501# else
b4e75104 502# define isinf(x) __MATH_TG ((x), __isinf, (x))
68337808 503# endif
bfce746a 504
12b64309
UD
505/* Bitmasks for the math_errhandling macro. */
506# define MATH_ERRNO 1 /* errno set by math functions. */
507# define MATH_ERREXCEPT 2 /* Exceptions raised by math functions. */
508
7b943af6
UD
509/* By default all functions support both errno and exception handling.
510 In gcc's fast math mode and if inline functions are defined this
511 might not be true. */
512# ifndef __FAST_MATH__
513# define math_errhandling (MATH_ERRNO | MATH_ERREXCEPT)
514# endif
515
ec751a23 516#endif /* Use ISO C99. */
377a515b 517
bf91be88 518#if __GLIBC_USE (IEC_60559_BFP_EXT)
29cb9293
JM
519# include <bits/iscanonical.h>
520
57267616 521/* Return nonzero value if X is a signaling NaN. */
a16e8bc0
GG
522# ifndef __cplusplus
523# define issignaling(x) __MATH_TG ((x), __issignaling, (x))
524# else
525 /* In C++ mode, __MATH_TG cannot be used, because it relies on
526 __builtin_types_compatible_p, which is a C-only builtin. On the
527 other hand, overloading provides the means to distinguish between
528 the floating-point types. The overloading resolution will match
529 the correct parameter (regardless of type qualifiers (i.e.: const
aa0235df 530 and volatile)). */
a16e8bc0
GG
531extern "C++" {
532inline int issignaling (float __val) { return __issignalingf (__val); }
533inline int issignaling (double __val) { return __issignaling (__val); }
3d7b66f6
GG
534inline int
535issignaling (long double __val)
536{
537# ifdef __NO_LONG_DOUBLE_MATH
538 return __issignaling (__val);
539# else
540 return __issignalingl (__val);
541# endif
542}
a16e8bc0
GG
543# if __HAVE_DISTINCT_FLOAT128
544inline int issignaling (_Float128 __val) { return __issignalingf128 (__val); }
545# endif
546} /* extern C++ */
547# endif
d942e95c
JM
548
549/* Return nonzero value if X is subnormal. */
550# define issubnormal(x) (fpclassify (x) == FP_SUBNORMAL)
bb8081f5
JM
551
552/* Return nonzero value if X is zero. */
b3918c44
FW
553# ifndef __cplusplus
554# ifdef __SUPPORT_SNAN__
555# define iszero(x) (fpclassify (x) == FP_ZERO)
556# else
557# define iszero(x) (((__typeof (x)) (x)) == 0)
558# endif
559# else /* __cplusplus */
e37208ce 560extern "C++" {
42496114
GG
561# ifdef __SUPPORT_SNAN__
562inline int
563iszero (float __val)
564{
565 return __fpclassifyf (__val) == FP_ZERO;
566}
567inline int
568iszero (double __val)
569{
570 return __fpclassify (__val) == FP_ZERO;
571}
572inline int
573iszero (long double __val)
574{
575# ifdef __NO_LONG_DOUBLE_MATH
576 return __fpclassify (__val) == FP_ZERO;
577# else
578 return __fpclassifyl (__val) == FP_ZERO;
579# endif
580}
581# if __HAVE_DISTINCT_FLOAT128
582inline int
583iszero (_Float128 __val)
584{
585 return __fpclassifyf128 (__val) == FP_ZERO;
586}
587# endif
588# else
b3918c44
FW
589template <class __T> inline bool
590iszero (__T __val)
591{
b3918c44 592 return __val == 0;
b3918c44 593}
42496114 594# endif
e37208ce 595} /* extern C++ */
b3918c44 596# endif /* __cplusplus */
bf91be88 597#endif /* Use IEC_60559_BFP_EXT. */
57267616 598
813378e9 599#ifdef __USE_XOPEN
377a515b 600/* X/Open wants another strange constant. */
813378e9
JM
601# define MAXFLOAT 3.40282347e+38F
602#endif
28f540f4 603
28f540f4 604
28f540f4 605/* Some useful constants. */
498afc54 606#if defined __USE_MISC || defined __USE_XOPEN
0a614877
UD
607# define M_E 2.7182818284590452354 /* e */
608# define M_LOG2E 1.4426950408889634074 /* log_2 e */
609# define M_LOG10E 0.43429448190325182765 /* log_10 e */
610# define M_LN2 0.69314718055994530942 /* log_e 2 */
611# define M_LN10 2.30258509299404568402 /* log_e 10 */
612# define M_PI 3.14159265358979323846 /* pi */
613# define M_PI_2 1.57079632679489661923 /* pi/2 */
614# define M_PI_4 0.78539816339744830962 /* pi/4 */
615# define M_1_PI 0.31830988618379067154 /* 1/pi */
616# define M_2_PI 0.63661977236758134308 /* 2/pi */
617# define M_2_SQRTPI 1.12837916709551257390 /* 2/sqrt(pi) */
618# define M_SQRT2 1.41421356237309504880 /* sqrt(2) */
619# define M_SQRT1_2 0.70710678118654752440 /* 1/sqrt(2) */
714a562f
UD
620#endif
621
0a614877
UD
622/* The above constants are not adequate for computation using `long double's.
623 Therefore we provide as an extension constants with similar names as a
9a24f906 624 GNU extension. Provide enough digits for the 128-bit IEEE quad. */
0a614877 625#ifdef __USE_GNU
2d10d547
JM
626# define M_El 2.718281828459045235360287471352662498L /* e */
627# define M_LOG2El 1.442695040888963407359924681001892137L /* log_2 e */
628# define M_LOG10El 0.434294481903251827651128918916605082L /* log_10 e */
629# define M_LN2l 0.693147180559945309417232121458176568L /* log_e 2 */
630# define M_LN10l 2.302585092994045684017991454684364208L /* log_e 10 */
631# define M_PIl 3.141592653589793238462643383279502884L /* pi */
632# define M_PI_2l 1.570796326794896619231321691639751442L /* pi/2 */
633# define M_PI_4l 0.785398163397448309615660845819875721L /* pi/4 */
634# define M_1_PIl 0.318309886183790671537767526745028724L /* 1/pi */
635# define M_2_PIl 0.636619772367581343075535053490057448L /* 2/pi */
636# define M_2_SQRTPIl 1.128379167095512573896158903121545172L /* 2/sqrt(pi) */
637# define M_SQRT2l 1.414213562373095048801688724209698079L /* sqrt(2) */
638# define M_SQRT1_2l 0.707106781186547524400844362104849039L /* 1/sqrt(2) */
0a614877 639#endif
710f7bab 640
fcee5905
PM
641#if __HAVE_FLOAT128 && defined __USE_GNU
642# define M_Ef128 __f128 (2.718281828459045235360287471352662498) /* e */
643# define M_LOG2Ef128 __f128 (1.442695040888963407359924681001892137) /* log_2 e */
644# define M_LOG10Ef128 __f128 (0.434294481903251827651128918916605082) /* log_10 e */
645# define M_LN2f128 __f128 (0.693147180559945309417232121458176568) /* log_e 2 */
646# define M_LN10f128 __f128 (2.302585092994045684017991454684364208) /* log_e 10 */
647# define M_PIf128 __f128 (3.141592653589793238462643383279502884) /* pi */
648# define M_PI_2f128 __f128 (1.570796326794896619231321691639751442) /* pi/2 */
649# define M_PI_4f128 __f128 (0.785398163397448309615660845819875721) /* pi/4 */
650# define M_1_PIf128 __f128 (0.318309886183790671537767526745028724) /* 1/pi */
651# define M_2_PIf128 __f128 (0.636619772367581343075535053490057448) /* 2/pi */
652# define M_2_SQRTPIf128 __f128 (1.128379167095512573896158903121545172) /* 2/sqrt(pi) */
653# define M_SQRT2f128 __f128 (1.414213562373095048801688724209698079) /* sqrt(2) */
654# define M_SQRT1_2f128 __f128 (0.707106781186547524400844362104849039) /* 1/sqrt(2) */
655#endif
28f540f4 656
00bc5db0
UD
657/* When compiling in strict ISO C compatible mode we must not use the
658 inline functions since they, among other things, do not set the
659 `errno' variable correctly. */
660#if defined __STRICT_ANSI__ && !defined __NO_MATH_INLINES
661# define __NO_MATH_INLINES 1
662#endif
663
1e6d0723
WD
664#ifdef __USE_ISOC99
665# if __GNUC_PREREQ (3, 1)
f4c024d1
UD
666/* ISO C99 defines some macros to compare number while taking care for
667 unordered numbers. Many FPUs provide special instructions to support
668 these operations. Generic support in GCC for these as builtins went
1e6d0723
WD
669 in 2.97, but not all cpus added their patterns until 3.1. Therefore
670 we enable the builtins from 3.1 onwards and use a generic implementation
671 othwerwise. */
672# define isgreater(x, y) __builtin_isgreater(x, y)
673# define isgreaterequal(x, y) __builtin_isgreaterequal(x, y)
674# define isless(x, y) __builtin_isless(x, y)
675# define islessequal(x, y) __builtin_islessequal(x, y)
676# define islessgreater(x, y) __builtin_islessgreater(x, y)
677# define isunordered(x, y) __builtin_isunordered(x, y)
678# else
679# define isgreater(x, y) \
680 (__extension__ ({ __typeof__ (x) __x = (x); __typeof__ (y) __y = (y); \
681 !isunordered (__x, __y) && __x > __y; }))
682# define isgreaterequal(x, y) \
683 (__extension__ ({ __typeof__ (x) __x = (x); __typeof__ (y) __y = (y); \
684 !isunordered (__x, __y) && __x >= __y; }))
685# define isless(x, y) \
686 (__extension__ ({ __typeof__ (x) __x = (x); __typeof__ (y) __y = (y); \
687 !isunordered (__x, __y) && __x < __y; }))
688# define islessequal(x, y) \
689 (__extension__ ({ __typeof__ (x) __x = (x); __typeof__ (y) __y = (y); \
690 !isunordered (__x, __y) && __x <= __y; }))
691# define islessgreater(x, y) \
692 (__extension__ ({ __typeof__ (x) __x = (x); __typeof__ (y) __y = (y); \
693 !isunordered (__x, __y) && __x != __y; }))
694/* isunordered must always check both operands first for signaling NaNs. */
695# define isunordered(x, y) \
696 (__extension__ ({ __typeof__ (x) __u = (x); __typeof__ (y) __v = (y); \
697 __u != __v && (__u != __u || __v != __v); }))
698# endif
f4c024d1
UD
699#endif
700
4d585333 701/* Get machine-dependent inline versions (if there are any). */
0c6cee5d 702#ifdef __USE_EXTERN_INLINES
478b92f0 703# include <bits/mathinline.h>
4d585333
RM
704#endif
705
0ac5ae23
UD
706/* Define special entry points to use when the compiler got told to
707 only expect finite results. */
708#if defined __FINITE_MATH_ONLY__ && __FINITE_MATH_ONLY__ > 0
f264cca5
GG
709
710/* Include bits/math-finite.h for double. */
711# define _Mdouble_ double
712# define __MATH_DECLARING_DOUBLE 1
33d523d7 713# define __MATH_DECLARING_FLOATN 0
7daada03
JM
714# define __REDIRFROM_X(function, reentrant) \
715 function ## reentrant
716# define __REDIRTO_X(function, reentrant) \
717 __ ## function ## reentrant ## _finite
0ac5ae23 718# include <bits/math-finite.h>
f264cca5
GG
719# undef _Mdouble_
720# undef __MATH_DECLARING_DOUBLE
33d523d7 721# undef __MATH_DECLARING_FLOATN
7daada03
JM
722# undef __REDIRFROM_X
723# undef __REDIRTO_X
f264cca5
GG
724
725/* When __USE_ISOC99 is defined, include math-finite for float and
726 long double, as well. */
727# ifdef __USE_ISOC99
728
729/* Include bits/math-finite.h for float. */
730# define _Mdouble_ float
731# define __MATH_DECLARING_DOUBLE 0
33d523d7 732# define __MATH_DECLARING_FLOATN 0
7daada03
JM
733# define __REDIRFROM_X(function, reentrant) \
734 function ## f ## reentrant
735# define __REDIRTO_X(function, reentrant) \
736 __ ## function ## f ## reentrant ## _finite
f264cca5
GG
737# include <bits/math-finite.h>
738# undef _Mdouble_
739# undef __MATH_DECLARING_DOUBLE
33d523d7 740# undef __MATH_DECLARING_FLOATN
7daada03
JM
741# undef __REDIRFROM_X
742# undef __REDIRTO_X
f264cca5
GG
743
744/* Include bits/math-finite.h for long double. */
1361e98d 745# ifdef __MATH_DECLARE_LDOUBLE
f264cca5
GG
746# define _Mdouble_ long double
747# define __MATH_DECLARING_DOUBLE 0
33d523d7 748# define __MATH_DECLARING_FLOATN 0
7daada03
JM
749# define __REDIRFROM_X(function, reentrant) \
750 function ## l ## reentrant
23761119 751# ifdef __NO_LONG_DOUBLE_MATH
7daada03
JM
752# define __REDIRTO_X(function, reentrant) \
753 __ ## function ## reentrant ## _finite
23761119 754# else
7daada03
JM
755# define __REDIRTO_X(function, reentrant) \
756 __ ## function ## l ## reentrant ## _finite
23761119 757# endif
f264cca5
GG
758# include <bits/math-finite.h>
759# undef _Mdouble_
760# undef __MATH_DECLARING_DOUBLE
33d523d7 761# undef __MATH_DECLARING_FLOATN
7daada03
JM
762# undef __REDIRFROM_X
763# undef __REDIRTO_X
f264cca5
GG
764# endif
765
766# endif /* __USE_ISOC99. */
33d523d7
GG
767
768/* Include bits/math-finite.h for float128. */
769# if (__HAVE_DISTINCT_FLOAT128 || (__HAVE_FLOAT128 && !defined _LIBC)) \
770 && __GLIBC_USE (IEC_60559_TYPES_EXT)
771# define _Mdouble_ _Float128
772# define __MATH_DECLARING_DOUBLE 0
33d523d7 773# define __MATH_DECLARING_FLOATN 1
7daada03
JM
774# define __REDIRFROM_X(function, reentrant) \
775 function ## f128 ## reentrant
23761119 776# if __HAVE_DISTINCT_FLOAT128
7daada03
JM
777# define __REDIRTO_X(function, reentrant) \
778 __ ## function ## f128 ## reentrant ## _finite
23761119 779# else
7daada03
JM
780# define __REDIRTO_X(function, reentrant) \
781 __ ## function ## l ## reentrant ## _finite
23761119 782# endif
33d523d7
GG
783# include <bits/math-finite.h>
784# undef _Mdouble_
785# undef __MATH_DECLARING_DOUBLE
33d523d7 786# undef __MATH_DECLARING_FLOATN
7daada03
JM
787# undef __REDIRFROM_X
788# undef __REDIRTO_X
33d523d7 789# endif
f264cca5 790#endif /* __FINITE_MATH_ONLY__ > 0. */
0ac5ae23 791
1e7c8fcc 792#if __GLIBC_USE (IEC_60559_BFP_EXT)
b4e75104
JM
793/* An expression whose type has the widest of the evaluation formats
794 of X and Y (which are of floating-point types). */
795# if __FLT_EVAL_METHOD__ == 2 || __FLT_EVAL_METHOD__ > 64
796# define __MATH_EVAL_FMT2(x, y) ((x) + (y) + 0.0L)
797# elif __FLT_EVAL_METHOD__ == 1 || __FLT_EVAL_METHOD__ > 32
798# define __MATH_EVAL_FMT2(x, y) ((x) + (y) + 0.0)
1e7c8fcc 799# else
b4e75104 800# define __MATH_EVAL_FMT2(x, y) ((x) + (y))
1e7c8fcc 801# endif
b4e75104
JM
802
803/* Return X == Y but raising "invalid" and setting errno if X or Y is
804 a NaN. */
805# define iseqsig(x, y) \
806 __MATH_TG (__MATH_EVAL_FMT2 (x, y), __iseqsig, ((x), (y)))
1e7c8fcc
JM
807#endif
808
4d585333
RM
809__END_DECLS
810
811
28f540f4 812#endif /* math.h */