Skip to main content

math.h

The functions of math.h provide some common math functions that you may need to use in your calculations. Think of these as common calculations you might find on your calculator. There are far more function than these in the math.h library. For a more thorough listing see:

https://en.cppreference.com/w/c/numeric/math.html

math.h Library Functions

FunctionPurposeExample
ceil(x)Returns smallest integer ≥ xxceil(4.3)5.05.0
floor(x)Returns largest integer ≤ xxfloor(4.7)4.04.0
round(x)Rounds xx to nearest integerround(4.5)5.05.0
fabs(x)Returns absolute value of xxfabs(-5.2)5.25.2
sqrt(x)Returns square root of xxsqrt(16.0)4.04.0
pow(x, y)Returns xx raised to power yypow(2.0, 3.0)8.08.0
exp(x)Returns exe^xexp(1.0)2.718...2.718...
log(x)Returns natural logarithm of xxlog(2.718)1.01.0
log10(x)Returns base-10 logarithm of xxlog10(100.0)2.02.0
sin(x)Returns sine of xx (radians)sin(0.0)0.00.0
cos(x)Returns cosine of xx (radians)cos(0.0)1.01.0
tan(x)Returns tangent of xx (radians)tan(0.0)0.00.0

Note: All trigonometric functions use radians, not degrees. To convert degrees to radians, multiply by π/180\pi/180.