7.12 Mathematics <math.h>
- 7.12.1 Treatment of error conditions
- 7.12.2 The FP_CONTRACT pragma
- 7.12.3 Classification macros
- 7.12.4 Trigonometric functions
- 7.12.5 Hyperbolic functions
- 7.12.6 Exponential and logarithmic functions
- 7.12.6.1 The exp functions
- 7.12.6.2 The exp2 functions
- 7.12.6.3 The expm1 functions
- 7.12.6.4 The frexp functions
- 7.12.6.5 The ilogb functions
- 7.12.6.6 The ldexp functions
- 7.12.6.7 The log functions
- 7.12.6.8 The log10 functions
- 7.12.6.9 The log1p functions
- 7.12.6.10 The log2 functions
- 7.12.6.11 The logb functions
- 7.12.6.12 The modf functions
- 7.12.6.13 The scalbn and scalbln functions
- 7.12.7 Power and absolute-value functions
- 7.12.8 Error and gamma functions
- 7.12.9 Nearest integer functions
- 7.12.10 Remainder functions
- 7.12.11 Manipulation functions
- 7.12.12 Maximum, minimum, and positive difference functions
- 7.12.13 Floating multiply-add
- 7.12.14 Comparison macros
The header <math.h> declares two types and many mathematical functions and defines several macros. Most synopses specify a family of functions consisting of a principal function with one or more double parameters, a double return value, or both; and other functions with the same name but with f and l suffixes, which are corresponding functions with float and long double parameters, return values, or both.[1] Integer arithmetic functions and conversion functions are discussed later.
The types
float_t
double_t
are floating types at least as wide as float and double, respectively, and such that double_t is at least as wide as float_t. If FLT_EVAL_METHOD equals 0, float_t and double_t are float and double, respectively; if FLT_EVAL_METHOD equals 1, they are both double; if FLT_EVAL_METHOD equals 2, they are both long double; and for other values of FLT_EVAL_METHOD, they are otherwise implementation-defined.[2]
The macro
HUGE_VAL
expands to a positive double constant expression, not necessarily representable as a float. The macros
HUGE_VALF
HUGE_VALL
are respectively float and long double analogs of HUGE_VAL.[3]
The macro
INFINITY
expands to a constant expression of type float representing positive or unsigned infinity, if available; else to a positive constant of type float that overflows at translation time.[4]
The macro
NAN
is defined if and only if the implementation supports quiet NaNs for the float type. It expands to a constant expression of type float representing a quiet NaN.
The number classification macros
FP_INFINITE
FP_NAN
FP_NORMAL
FP_SUBNORMAL
FP_ZERO
represent the mutually exclusive kinds of floating-point values. They expand to integer constant expressions with distinct values. Additional implementation-defined floating- point classifications, with macro definitions beginning with FP_ and an uppercase letter, may also be specified by the implementation.
The macro
FP_FAST_FMA
is optionally defined. If defined, it indicates that the fma function generally executes about as fast as, or faster than, a multiply and an add of double operands.[5] The macros
FP_FAST_FMAF
FP_FAST_FMAL
are, respectively, float and long double analogs of FP_FAST_FMA. If defined, these macros expand to the integer constant 1.
The macros
FP_ILOGB0
FP_ILOGBNAN
expand to integer constant expressions whose values are returned by ilogb(x) if x is zero or NaN, respectively. The value of FP_ILOGB0 shall be either INT_MIN or -INT_MAX. The value of FP_ILOGBNAN shall be either INT_MAX or INT_MIN.
The macros
MATH_ERRNO
MATH_ERREXCEPT
expand to the integer constants 1 and 2, respectively; the macro
math_errhandling
expands to an expression that has type int and the value MATH_ERRNO, MATH_ERREXCEPT, or the bitwise OR of both. The value of math_errhandling is constant for the duration of the program. It is unspecified whether math_errhandling is a macro or an identifier with external linkage. If a macro definition is suppressed or a program defines an identifier with the name math_errhandling, the behavior is undefined. If the expression math_errhandling & MATH_ERREXCEPT can be nonzero, the implementation shall define the macros FE_DIVBYZERO, FE_INVALID, and FE_OVERFLOW in <fenv.h>.
Footnotes