Common mathematical functions – cppreference.com

Defined in header <stdlib.h>

abs

labs

llabs

(C99)

computes absolute value of an integral value (

\(\small{|x|}\)

|x|

)

(function)

div

ldiv

lldiv

(C99)

computes quotient and remainder of integer division

(function)

Defined in header <inttypes.h>

imaxabs

(C99)

computes absolute value of an integral value (

\(\small{|x|}\)

|x|

)

(function)

imaxdiv

(C99)

computes quotient and remainder of integer division

(function)

Defined in header <math.h>

Basic operations

fabs

fabsf

fabsl

(C99)

(C99)

computes absolute value of a floating-point value (

\(\small{|x|}\)

|x|

)

(function)

fmod

fmodf

fmodl

(C99)

(C99)

computes remainder of the floating-point division operation

(function)

remainder

remainderf

remainderl

(C99)

(C99)

(C99)

computes signed remainder of the floating-point division operation

(function)

remquo

remquof

remquol

(C99)

(C99)

(C99)

computes signed remainder as well as the three last bits of the division operation

(function)

fma

fmaf

fmal

(C99)

(C99)

(C99)

computes fused multiply-add operation

(function)

fmax

fmaxf

fmaxl

(C99)

(C99)

(C99)

determines larger of two floating-point values

(function)

fmin

fminf

fminl

(C99)

(C99)

(C99)

determines smaller of two floating-point values

(function)

fdim

fdimf

fdiml

(C99)

(C99)

(C99)

determines positive difference of two floating-point values (

\({\small\max{(0, x-y)} }\)

max(0, x-y)

)

(function)

nan

nanf

nanl

(C99)

(C99)

(C99)

returns a NaN (not-a-number)

(function)

Exponential functions

exp

expf

expl

(C99)

(C99)

computes e raised to the given power (

\({\small e^x}\)

ex

)

(function)

exp2

exp2f

exp2l

(C99)

(C99)

(C99)

computes 2 raised to the given power (

\({\small 2^x}\)

2x

)

(function)

expm1

expm1f

expm1l

(C99)

(C99)

(C99)

computes e raised to the given power, minus one (

\({\small e^x-1}\)

ex-1

)

(function)

log

logf

logl

(C99)

(C99)

computes natural (base-e) logarithm (

\({\small \ln{x} }\)

ln(x)

)

(function)

log10

log10f

log10l

(C99)

(C99)

computes common (base-10) logarithm (

\({\small \log_{10}{x} }\)

log10(x)

)

(function)

log2

log2f

log2l

(C99)

(C99)

(C99)

computes base-2 logarithm (

\({\small \log_{2}{x} }\)

log2(x)

)

(function)

log1p

log1pf

log1pl

(C99)

(C99)

(C99)

computes natural (base-e) logarithm of 1 plus the given number (

\({\small \ln{(1+x)} }\)

ln(1+x)

)

(function)

Power functions

pow

powf

powl

(C99)

(C99)

computes a number raised to the given power (

\(\small{x^y}\)

xy

)

(function)

sqrt

sqrtf

sqrtl

(C99)

(C99)

computes square root (

\(\small{\sqrt{x} }\)

x

)

(function)

cbrt

cbrtf

cbrtl

(C99)

(C99)

(C99)

computes cubic root (

\(\small{\sqrt[3]{x} }\)

3

x

)

(function)

hypot

hypotf

hypotl

(C99)

(C99)

(C99)

computes square root of the sum of the squares of two given numbers (

\(\scriptsize{\sqrt{x^2+y^2} }\)

x

2

+y

2

)

(function)

Trigonometric functions

sin

sinf

sinl

(C99)

(C99)

computes sine (

\({\small\sin{x} }\)

sin(x)

)

(function)

cos

cosf

cosl

(C99)

(C99)

computes cosine (

\({\small\cos{x} }\)

cos(x)

)

(function)

tan

tanf

tanl

(C99)

(C99)

computes tangent (

\({\small\tan{x} }\)

tan(x)

)

(function)

asin

asinf

asinl

(C99)

(C99)

computes arc sine (

\({\small\arcsin{x} }\)

arcsin(x)

)

(function)

acos

acosf

acosl

(C99)

(C99)

computes arc cosine (

\({\small\arccos{x} }\)

arccos(x)

)

(function)

atan

atanf

atanl

(C99)

(C99)

computes arc tangent (

\({\small\arctan{x} }\)

arctan(x)

)

(function)

atan2

atan2f

atan2l

(C99)

(C99)

computes arc tangent, using signs to determine quadrants

(function)

Hyperbolic functions

sinh

sinhf

sinhl

(C99)

(C99)

computes hyperbolic sine (

\({\small\sinh{x} }\)

sinh(x)

)

(function)

cosh

coshf

coshl

(C99)

(C99)

computes hyperbolic cosine (

\({\small\cosh{x} }\)

cosh(x)

)

(function)

tanh

tanhf

tanhl

(C99)

(C99)

computes hyperbolic tangent (

\({\small\tanh{x} }\)

tanh(x)

)

(function)

asinh

asinhf

asinhl

(C99)

(C99)

(C99)

computes inverse hyperbolic sine (

\({\small\operatorname{arsinh}{x} }\)

arsinh(x)

)

(function)

acosh

acoshf

acoshl

(C99)

(C99)

(C99)

computes inverse hyperbolic cosine (

\({\small\operatorname{arcosh}{x} }\)

arcosh(x)

)

(function)

atanh

atanhf

atanhl

(C99)

(C99)

(C99)

computes inverse hyperbolic tangent (

\({\small\operatorname{artanh}{x} }\)

artanh(x)

)

(function)

Error and gamma functions

erf

erff

erfl

(C99)

(C99)

(C99)

computes error function

(function)

erfc

erfcf

erfcl

(C99)

(C99)

(C99)

computes complementary error function

(function)

tgamma

tgammaf

tgammal

(C99)

(C99)

(C99)

computes gamma function

(function)

lgamma

lgammaf

lgammal

(C99)

(C99)

(C99)

computes natural (base-e) logarithm of the gamma function

(function)

Nearest integer floating-point operations

ceil

ceilf

ceill

(C99)

(C99)

computes smallest integer not less than the given value

(function)

floor

floorf

floorl

(C99)

(C99)

computes largest integer not greater than the given value

(function)

trunc

truncf

truncl

(C99)

(C99)

(C99)

rounds to nearest integer not greater in magnitude than the given value

(function)

round

roundf

roundl

lround

lroundf

lroundl

llround

llroundf

llroundl

(C99)

(C99)

(C99)

(C99)

(C99)

(C99)

(C99)

(C99)

(C99)

rounds to nearest integer, rounding away from zero in halfway cases

(function)

nearbyint

nearbyintf

nearbyintl

(C99)

(C99)

(C99)

rounds to an integer using current rounding mode

(function)

rint

rintf

rintl

lrint

lrintf

lrintl

llrint

llrintf

llrintl

(C99)

(C99)

(C99)

(C99)

(C99)

(C99)

(C99)

(C99)

(C99)

rounds to an integer using current rounding mode with
exception if the result differs

(function)

Floating-point manipulation functions

frexp

frexpf

frexpl

(C99)

(C99)

breaks a number into significand and a power of

2

(function)

ldexp

ldexpf

ldexpl

(C99)

(C99)

multiplies a number by

2

raised to a power

(function)

modf

modff

modfl

(C99)

(C99)

breaks a number into integer and fractional parts

(function)

ilogb

ilogbf

ilogbl

(C99)

(C99)

(C99)

extracts exponent of the given number

(function)

logb

logbf

logbl

(C99)

(C99)

(C99)

extracts exponent of the given number

(function)

nextafter

nextafterf

nextafterl

nexttoward

nexttowardf

nexttowardl

(C99)

(C99)

(C99)

(C99)

(C99)

(C99)

determines next representable floating-point value towards the given value

(function)

copysign

copysignf

copysignl

(C99)

(C99)

(C99)

produces a value with the magnitude of a given value and the sign of another given value

(function)

Classification and comparison

fpclassify

(C99)

classifies the given floating-point value

(function macro)

isfinite

(C99)

checks if the given number has finite value

(function macro)

isinf

(C99)

checks if the given number is infinite

(function macro)

isnan

(C99)

checks if the given number is NaN

(function macro)

isnormal

(C99)

checks if the given number is normal

(function macro)

signbit

(C99)

checks if the given number is negative

(function macro)

isgreater

(C99)

checks if the first floating-point argument is greater than the second

(function macro)

isgreaterequal

(C99)

checks if the first floating-point argument is greater or equal than the second

(function macro)

isless

(C99)

checks if the first floating-point argument is less than the second

(function macro)

islessequal

(C99)

checks if the first floating-point argument is less or equal than the second

(function macro)

islessgreater

(C99)

checks if the first floating-point argument is less or greater than the second

(function macro)

isunordered

(C99)

checks if two floating-point values are unordered

(function macro)