Overview of Functions
Most of the mathematical functions are placed in math.h
header (cmath
header in C++). The functions that operate on integers, such as abs
, labs
, div
, and ldiv
, are instead specified in the stdlib.h
header (cstdlib
header in C++).
Any functions that operate on angles use radians as the unit of angle.
Not all functions are available in C89 version of the C standard. For those that are, the functions accept only type double
for the floating-point arguments. In C99, this limitation 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.
Function | Description | |
---|---|---|
abs labs llabs |
computes absolute value of an integer value | |
fabs |
computes absolute value of a floating point value | |
div ldiv lldiv |
computes the quotient and remainder of integer division | |
fmod |
remainder of the floating point division operation | |
remainder |
signed remainder of the division operation | |
remquo |
signed remainder as well as the three last bits of the division operation | |
fma |
fused multiply-add operation | |
fmax |
larger of two floating point values | |
fmin |
smaller of two floating point values | |
fdim |
positive difference of two floating point values | |
nan nanf nanl |
returns a not-a-number (NaN) | |
Exponential functions |
exp |
returns e raised to the given power |
exp2 |
returns 2 raised to the given power | |
expm1 |
returns e raised to the given power, minus one | |
log |
computes natural (base e) logarithm (to base e) | |
log2 |
computes common (base 2) logarithm | |
log10 |
computes common (base 10) logarithm | |
log1p |
computes natural logarithm (to base e) of 1 plus the given number | |
ilogb |
extracts exponent of the number | |
logb |
extracts exponent of the number | |
Power functions |
sqrt |
computes square root |
cbrt |
computes cubic root | |
hypot |
computes square root of the sum of the squares of two given numbers | |
pow |
raises a number to the given power | |
Trigonometric functions |
sin |
computes sine |
cos |
computes cosine | |
tan |
computes tangent | |
asin |
computes arc sine | |
acos |
computes arc cosine | |
atan |
computes arc tangent | |
atan2 |
computes arc tangent, using signs to determine quadrants | |
Hyperbolic functions |
sinh |
computes hyperbolic sine |
cosh |
computes hyperbolic cosine | |
tanh |
computes hyperbolic tangent | |
asinh |
computes hyperbolic arc sine | |
acosh |
computes hyperbolic arc cosine | |
atanh |
computes hyperbolic arc tangent | |
Error and gamma functions |
erf |
computes error function |
erfc |
computes complementary error function | |
lgamma |
computes natural logarithm of the gamma function | |
tgamma |
computes gamma function | |
Nearest integer floating point operations |
ceil |
returns the nearest integer not less than the given value |
floor |
returns the nearest integer not greater than the given value | |
trunc |
returns the nearest integer not greater in magnitude than the given value | |
round lround llround |
returns the nearest integer, rounding away from zero in halfway cases | |
nearbyint |
returns the nearest integer using current rounding mode | |
rint lrint llrint |
returns the nearest integer using current rounding mode with exception if the result differs | |
Floating point manipulation functions |
frexp |
decomposes a number into significand and a power of 2 |
ldexp |
multiplies a number by 2 raised to a power | |
modf |
decomposes a number into integer and fractional parts | |
scalbn scalbln |
multiplies a number by FLT_RADIX raised to a power | |
nextafter nexttoward |
returns next representable floating point value towards the given value | |
copysign |
copies the sign of a floating point value | |
Classification | fpclassify |
categorizes the given floating point value |
isfinite |
checks if the given number has finite value | |
isinf |
checks if the given number is infinite | |
isnan |
checks if the given number is NaN | |
isnormal |
checks if the given number is normal | |
signbit |
checks if the given number is negative |
Read more about this topic: C Mathematical Functions
Famous quotes containing the word functions:
“Mark the babe
Not long accustomed to this breathing world;
One that hath barely learned to shape a smile,
Though yet irrational of soul, to grasp
With tiny fingerto let fall a tear;
And, as the heavy cloud of sleep dissolves,
To stretch his limbs, bemocking, as might seem,
The outward functions of intelligent man.”
—William Wordsworth (17701850)