C++ Math Functions

Beginner
8 min read
Updated: Nov 2026
70 function guides
Function index

About This Index

This page is the C++ Math Functions index. Each row links to a full guide with syntax, parameters, return value, three examples, and FAQs.

Learn what <cmath> is on /cpp/math. Use this page when you need a specific function such as sqrt(), pow(), or floor().

Include <cmath> and write std::.

All of these functions live in <cmath> and in the std namespace, so you write std::sqrt(x). Most take a double, and angles are in radians. A bad input gives NaN or infinity instead of a crash. The 70 functions are listed below.

How to Call a Math Function

Include <cmath>, then call the function with std:: in front:

C++
#include <cmath>
#include <iostream>

double root  = std::sqrt(16.0);       // 4
double power = std::pow(2.0, 10.0);   // 1024
double dist  = std::abs(-7.5);        // 7.5
double down  = std::floor(3.9);       // 3
double up    = std::ceil(3.1);        // 4
double sine  = std::sin(0.0);         // 0 (radians)
bool   bad   = std::isnan(std::sqrt(-1.0));   // true

C++ Math Functions Table

All function guides in this C++ tutorial series (70 tutorials), grouped by purpose.

Absolute value and sign

4 functions

Remove a minus sign, copy a sign, or ask whether a number is negative.

FunctionDescriptionTutorial
abs()Remove the minus sign from a number.Try it
fabs()Absolute value of a floating-point number.Try it
copysign()Take the size of one number and the sign of another.Try it
signbit()Check if a number has a negative sign.Try it

Roots and powers

4 functions

Square roots, cube roots, powers, and the length of a right triangle side.

FunctionDescriptionTutorial
sqrt()Square root of a number.Try it
cbrt()Cube root of a number.Try it
pow()Raise a number to a power.Try it
hypot()Length of the hypotenuse of a right triangle.Try it

Exponential and logarithm

9 functions

Powers of e and of 2, and logarithms in base e, 10, and 2.

FunctionDescriptionTutorial
exp()The number e raised to a power.Try it
exp2()Two raised to a power.Try it
expm1()e to the power x, minus 1, with high accuracy.Try it
log()Natural logarithm (base e) of a number.Try it
log10()Base-10 logarithm of a number.Try it
log2()Base-2 logarithm of a number.Try it
log1p()Natural logarithm of 1 plus x, with high accuracy.Try it
logb()The binary exponent of a number, as a double.Try it
ilogb()The binary exponent of a number, as an int.Try it

Trigonometry

7 functions

Sine, cosine, tangent, and their inverses. Angles are in radians.

FunctionDescriptionTutorial
sin()Sine of an angle in radians.Try it
cos()Cosine of an angle in radians.Try it
tan()Tangent of an angle in radians.Try it
asin()Inverse sine, as an angle in radians.Try it
acos()Inverse cosine, as an angle in radians.Try it
atan()Inverse tangent, as an angle in radians.Try it
atan2()Angle of a point (x, y), in the correct quadrant.Try it

Hyperbolic functions

6 functions

Hyperbolic sine, cosine, tangent, and their inverses.

FunctionDescriptionTutorial
sinh()Hyperbolic sine of a number.Try it
cosh()Hyperbolic cosine of a number.Try it
tanh()Hyperbolic tangent of a number.Try it
asinh()Inverse hyperbolic sine of a number.Try it
acosh()Inverse hyperbolic cosine of a number.Try it
atanh()Inverse hyperbolic tangent of a number.Try it

Rounding

11 functions

Turn a double into a whole number: ceil, floor, trunc, round, and the rint family.

FunctionDescriptionTutorial
ceil()Round a number up to the next whole number.Try it
floor()Round a number down to the next whole number.Try it
trunc()Cut off the decimal part of a number.Try it
round()Round a number to the nearest whole number.Try it
nearbyint()Round using the current rounding mode.Try it
rint()Round using the current rounding mode.Try it
lrint()Round to the nearest long integer.Try it
llrint()Round to the nearest long long integer.Try it
lround()Round to the nearest long, halves away from zero.Try it
llround()Round to the nearest long long, halves away from zero.Try it
modf()Split a number into whole and fractional parts.Try it

Remainder, scale, and compare

13 functions

Remainders, powers of two, neighbours, fused multiply-add, and larger or smaller of two numbers.

FunctionDescriptionTutorial
fmod()Remainder of a division of two decimal numbers.Try it
remainder()IEEE remainder: x minus the nearest multiple of y.Try it
remquo()IEEE remainder plus the low bits of the quotient.Try it
frexp()Split a number into a mantissa and a power of two.Try it
ldexp()Multiply a number by a power of two.Try it
scalbn()Multiply a number by the radix raised to an int power.Try it
scalbln()Like scalbn(), but the power is a long.Try it
nextafter()The next representable number after x, toward y.Try it
nexttoward()Like nextafter(), but the direction is a long double.Try it
fma()Multiply and add in one step: x * y + z.Try it
fdim()Positive difference of two numbers (never below 0).Try it
fmax()The larger of two numbers, ignoring NaN.Try it
fmin()The smaller of two numbers, ignoring NaN.Try it

Classification and comparison

12 functions

Check for NaN, infinity, and normal numbers, and compare safely when NaN is possible.

FunctionDescriptionTutorial
fpclassify()Tells whether a number is normal, zero, subnormal, infinite, or NaN.Try it
isfinite()Checks that a number is not infinity and not NaN.Try it
isinf()Checks if a number is positive or negative infinity.Try it
isnan()Checks if a number is NaN (not a number).Try it
isnormal()Checks that a number is normal: not zero, subnormal, inf, or NaN.Try it
isgreater()Checks x > y safely, false if either is NaN.Try it
isgreaterequal()Checks x >= y safely, false if either is NaN.Try it
isless()Checks x < y safely, false if either is NaN.Try it
islessequal()Checks x <= y safely, false if either is NaN.Try it
islessgreater()Checks x < y or x > y, false if either is NaN.Try it
isunordered()Checks if x and y cannot be compared because one is NaN.Try it
nan()Creates a quiet NaN (not a number) value.Try it

Special functions

4 functions

The error function and the gamma function.

FunctionDescriptionTutorial
erf()The error function, used in statistics and probability.Try it
erfc()The complementary error function, 1 - erf(x), kept accurate.Try it
tgamma()The gamma function: a smooth factorial for decimal numbers.Try it
lgamma()The natural logarithm of the gamma function, for big factorials.Try it

Frequently Asked Questions

They are the math functions you get with #include <cmath>, such as std::sqrt(), std::pow(), std::sin(), std::floor(), and std::log(). Most of them take a double and return a double.
This tutorial series covers 70 functions: absolute value and sign, roots and powers, exponentials and logarithms, trigonometry, hyperbolic functions, rounding, remainder and scaling, classification and comparison, and special functions such as erf and tgamma.
Radians. std::sin(90.0) is not 1. Convert degrees first: radians = degrees * std::numbers::pi / 180. std::numbers::pi needs C++20 and #include <numbers>.
Most functions return NaN, for example std::sqrt(-1.0) or std::log(-1.0). Some return inf, for example std::log(0.0) gives -inf. Use std::isnan() and std::isinf() to check the result.
Read the C++ cmath page first. Then open sqrt(), pow(), abs(), floor(), and round() from the tables below.

Start with sqrt()

Take the square root of a number, the most common cmath function.

sqrt() tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

12 people found this page helpful