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.

image with no caption

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 ...

Get C++ In a Nutshell now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.