C mathematical operations are a group of functions in the standard library of the C programming language implementing basic mathematical functions. All functions use floating point numbers in one manner or another. Different C standards provide different, albeit backwards-compatible, sets of functions. Most of these functions are also available in the C++ standard library, though in different headers (the C headers are included as well, but only as a deprecated compatibility feature).
Most of the mathematical functions are defined in math.h
(cmath
header in C++). The functions that operate on integers, such as abs
, labs
, div
, and ldiv
, are instead defined in the stdlib.h
header (cstdlib
header in C++).
Any functions that operate on angles use radians as the unit of angle.
Not all of these functions are available in the C89 version of the standard. For those that are, the functions accept only type double
for the floating-point arguments, leading to expensive type conversions in code that otherwise used single-precision float
values. In C99, this shortcoming was fixed by introducing new sets of functions that work on float
and long double
arguments. Those functions are identified by f
and l
suffixes respectively.
C99 adds several functions and types for fine-grained control of floating point environment. These functions can be used to control a variety of settings that affect floating-point computations, for example, the rounding mode, on what conditions exceptions occur, when numbers are flushed to zero, etc. The floating point environment functions and types are defined in fenv.h
header (cfenv
in C++).
C99 adds a new _Complex
keyword (and complex
convenience macro) that provides support for complex numbers. Any floating point type can be modified with complex
, and is then defined as a pair of floating point numbers. Note that C99 and C++ do not implement complex numbers in a code-compatible way - the latter instead provides the class std::complex
.