The <cmath>
header declares a number of mathematical functions (from
the C standard <math.h>
). In
addition to the standard C function, most functions have overloaded
versions for different parameter types; each function's syntax shows all
the overloaded versions.
If an argument is out of range, a domain error occurs. The
function sets errno
to EDOM
and returns an error value. The value is
defined by the implementation, so the only portable way to test for a
domain error is to check errno
. If
the function's result is an overflow, a range error occurs. The function
returns HUGE_VAL
and sets errno
to ERANGE
. If underflow occurs, the function
returns 0
and may or may not set
errno
to ERANGE
. (See <cerrno>
for more information about
errno
.)
HUGE_VAL
is defined to be a
double
, and the C++ standard does
not define a suitable value for the float
and long
double
versions of the math functions. If
you are using a system that has infinity as an explicit floating-point
value (such as IEC 60559/IEEE 754, which is found on PCs, Macintoshes,
and modern workstations), the overloaded versions of a function
probably return infinity for overflow, so there is no problem with the
float
and long
double
versions of the functions. For
maximum portability, however, use only the double
versions of the math
functions.
All the trigonometric functions use radians. The descriptions of
these functions use the common mathematical notation for ranges of
values. [x
, y
) represents all values z
such that x
≤ z
< y
—that is, the square bracket
denotes an inclusive endpoint of a range, and the parenthesis denotes an
exclusive endpoint of a range.
Several other headers in the standard library declare additional mathematical functions:
<cfloat>
Declares macros for the limits of floating-point types
<climits>
Declares macros for the limits of integer types
<complex>
Declares types and functions for working with complex numbers
<cstdlib>
Declares integer absolute value functions and functions that compute a quotient and remainder in a single operation
<limits>
Declares the numeric_limits
class template for the
limits of the numerical types—e.g., the largest float
, the precision of double
, and so on
<numeric>
Declares generic numerical algorithms
<valarray>
Declares types and functions for computation with arrays of numbers