C Standard Library

C - <math.h>



The C language has a number of functions and macros that are available for mathematical operation. These functions are available to use in a current program after including the header file - #include <math.h>. All functions and macros of this header file are listed below:

Library Functions

Rounding & remainder Functions

FunctionsDescription
ceil() Rounds the given number up to the nearest integer.
floor() Rounds the given number down to the nearest integer.
fmod() Computes remainder of a division.
remainder() Computes remainder of a division.
remquo() Computes remainder and quotient of a division.
trunc() Rounds the given number towards zero.
nearbyint() Rounds the given number to nearby integral value.
rint() Rounds the given number to nearby integral value.
lrint() Rounds and cast the given number to long int value.
llrint() Rounds and cast the given number to long long int value.
round() Rounds the given number to nearby integral value.
lround() Rounds and casts the given number to long int value.
llround() Rounds and casts the given number to long long int value.

Trigonometric Functions

FunctionsDescription
sin() Returns the trigonometric sine of an angle in radians.
cos() Returns the trigonometric cosine of an angle in radians.
tan() Returns the trigonometric tangent of an angle in radians.
asin() Returns the arc sine of a value.
acos() Returns the arc cosine of a value.
atan() Returns the arc tangent of a value.
atan2() Returns the angle theta from the conversion of rectangular coordinates (x, y) to polar coordinates (r, theta).

Hyperbolic Functions

FunctionsDescription
sinh() Returns the hyperbolic sine of a value.
cosh() Returns the hyperbolic cosine of a value.
tanh() Returns the hyperbolic tangent of a value.
asinh() Returns the inverse hyperbolic sine of a value
acosh() Returns the inverse hyperbolic cosine of a value
atanh() Returns the inverse hyperbolic tangent of a value

Exponential & Logarithmic Functions

FunctionsDescription
exp() Returns the exponent of e.
frexp() Get significand and exponent.
ldexp() Generate value from significand and exponent.
modf() Break the given number into fractional and integral parts.
expm1() Returns the exponent of e minus 1, i.e., ex-1.
exp2() Returns the exponent of 2, i.e., 2x.
exp10() Returns the exponent of 10, i.e., 10x.
log() Returns the natural logarithm of a given number.
log10() Returns the base-10 logarithm of a given number.
log1p() Returns the natural logarithm of (1+number), i.e., log(1+number).
log2() Returns the base-2 (binary) logarithm of a given number.
logb() Returns the floating-point base logarithm of a given number.
ilogb() Returns the integer part of the floating-point base logarithm of a given number.
scalbn() Scale significand using floating-point base exponent.
scalbln() Scale significand using floating-point base exponent (long).

Power Functions

FunctionsDescription
pow() Returns base raised to the power of exponent.
sqrt() Returns the square root of the given number.
cbrt() Returns the cube root of the given number.
hypot() Returns square root of sum of squares of two arguments, i.e., sqrt(x2 +y2).

Error & gamma Functions

FunctionsDescription
erf() Returns the error function of the argument.
erfc() Returns the complementary error function of the argument.
tgamma() Returns gamma function of the argument.
lgamma() Returns log-gamma function of the argument.

Other Functions

FunctionsDescription
copysign() Returns a number with magnitude of first argument and sign of second argument.
fabs() Returns the absolute (positive) value of the given number.
fdim() Returns positive difference.
fma() Fused multiply-add operation.
fmax() Returns the number with maximum value.
fmin() Returns the number with minimum value.
nan() Generate quiet NaN.
nextafter() Returns next representable value.
nexttoward() Returns next representable value toward precise value.

Library Macros

Classification Macros/Functions

These macros are implemented as functions in C++.

MacrosDescription
fpclassify() Classify floating-point value.
isfinite() Check if the argument is finite or not.
isinf() Check if the argument is infinity or not.
isnan() Check if the argument is Not-a-Number (NaN) or not.
isnormal() Check if the argument is normal or not.
signbit() Check if the argument is negative or not.

Comparison Macros/Functions

These macros are implemented as functions in C++.

MacrosDescription
isgreater() Returns true if the first argument is greater than the second argument, else returns false.
isgreaterequal() Returns true if the first argument is greater than or equal to the second argument, else returns false.
isless() Returns true if the first argument is less than the second argument, else returns false.
islessequal() Returns true if the first argument is less than or equal to the second argument, else returns false.
islessgreater() Returns true if the first argument is less than or greater than the second argument, else returns false.
isunordered() Returns true if one or both arguments are unordered value, else returns false.

Macro constants

MacrosDescription
math_errhandling
MATH_ERRNO
MATH_ERREXCEPT
Defines the error handling mechanism used by the common mathematical functions.
HUGE_VAL
HUGE_VALF
HUGE_VALL
Indicates the overflow value for double, float and long double respectively.
FP_FAST_FMA
FP_FAST_FMAF
FP_FAST_FMAL
When defined, function fma() evaluates faster (in addition to being more precise) than the expression (x*y) + z for type double, float and long double respectively.
FP_NAN
FP_INFINITE
FP_ZERO
FP_SUBNORMAL
FP_NORMAL
Distinct category of floating-point numbers and possible values returned by fpclassify macro.
FP_ILOGB0
FP_ILOGBNAN
In special cases, values returned by ilogb() function.
INFINITY Evaluates to positive infinity or the value guaranteed to overflow a float.
NAN Evaluates to a quiet NaN of type float.

Library Types

TypesDescription
double_t Floating-point type.
float_t Floating-point type.