C Math Functions

Beginner
8 min read
Updated: Nov 2026
80 tutorials
<math.h>

Definition and Usage

C math functions are the library calls you use for floating-point work: roots, powers, logs, trigonometry, rounding, and remainders. Most live in <math.h> and return double. Integer abs() lives in <stdlib.h> instead.

Lesson vs this index

The C Math page is the lesson: how to include math.h, link with -lm, use radians, and practice with examples. This page is the functions index—80 tutorials grouped by job. Open a row for syntax, examples, and FAQs for that one function.

What should beginners open first?

After the overview, start with fabs(), sqrt(), pow(), and sin(). Those cover absolute value, roots, powers, and basic trigonometry (after converting degrees to radians).

Need setup help?

Compile tips, radians, and five worked examples are on C Math—not repeated here.

Trig uses radians.

Convert first: rad = deg * M_PI / 180.0 before sin / cos / tan.

Pick the right abs.

abs() for int; fabs() for double.

C Syntax

Every math.h call follows the same pattern—include, call, link:

C
#include <math.h>
#include <stdio.h>

int main(void) {
    double root = sqrt(25.0);
    double power = pow(2.0, 10.0);

    printf("sqrt(25) = %.0f\n", root);
    printf("2^10     = %.0f\n", power);

    return 0;
}
/* gcc math_call.c -std=c11 -o math_call -lm */

Individual function pages show signatures, edge cases, and more examples. Use the tables below to jump to the right guide.

Choose a Function by Job

Not sure which tutorial to open? Match the job to a function:

JobPrefer
Distance / radiussqrt() or hypot()
Powers / growthpow(), exp()
Anglessin(), cos() after degree→radian
Quadrant-aware angleatan2() instead of atan()
Snap / gridsfloor(), ceil(), trunc()
Float compare tolerancefabs(a - b) < epsilon with fabs()
Integer magnitudeabs() from <stdlib.h>

Quick results cheat sheet

CallResult
sqrt(25.0)5.0
pow(2.0, 10.0)1024.0
sin(M_PI / 2.0)1.0 (90° in radians)
fabs(-3.14)3.14
floor(-2.7)-3.0 (toward −infinity)
trunc(-2.7)-2.0 (toward zero)
hypot(3.0, 4.0)5.0

Jump to a category

How to Browse This Index

A practical path through the C math function tutorials:

  1. If you still need -lm or radians, open the C Math lesson first.
  2. Use Choose a Function by Job when you know the task but not the name.
  3. Use the search box below when you already know the function name.
  4. Browse categories when you want related APIs (for example all rounding helpers).
  5. Open a tutorial for syntax, three examples, output, and FAQs—then return here for the next one.

C Math Functions Index

80 tutorials. Search by name or scroll the categories. Each row opens a full guide.

Absolute Value

2 functions

Remove the sign—integer abs() in stdlib.h and floating-point fabs() in math.h.

FunctionDescriptionTutorial
abs()Absolute value of int (stdlib.h).Try it
fabs()Absolute value of double.Try it

Roots & Powers

3 functions

Square roots, cube roots, and raise a number to any exponent.

FunctionDescriptionTutorial
sqrt()Square root of x.Try it
cbrt()Cube root of x.Try it
pow()x raised to the power y.Try it

Exponential & Logarithm

9 functions

Natural exponent, logs, and accurate helpers for small values.

FunctionDescriptionTutorial
exp()e raised to the power x.Try it
exp2()2 raised to the power x.Try it
expm1()exp(x) - 1, accurate for small x.Try it
log()Natural logarithm (base e).Try it
log10()Base-10 logarithm.Try it
log2()Base-2 logarithm.Try it
log1p()log(1 + x), accurate for small x.Try it
logb()Exponent of x as a double.Try it
ilogb()Exponent of x as an int.Try it

Circular Trigonometry

7 functions

Sine, cosine, tangent, and inverses—angles in radians unless you convert from degrees.

FunctionDescriptionTutorial
sin()Sine of angle in radians.Try it
cos()Cosine of angle in radians.Try it
tan()Tangent; undefined when cos = 0.Try it
asin()Arcsine; result in radians.Try it
acos()Arccosine; result in radians.Try it
atan()Arctangent of one value.Try it
atan2()Angle from (y, x) in radians.Try it

Hyperbolic Functions

6 functions

sinh, cosh, tanh and inverses—not the same as circular trig despite similar names.

FunctionDescriptionTutorial
sinh()Hyperbolic sine.Try it
cosh()Hyperbolic cosine.Try it
tanh()Hyperbolic tangent; output in (-1, 1).Try it
asinh()Inverse hyperbolic sine.Try it
acosh()Inverse hyperbolic cosine.Try it
atanh()Inverse hyperbolic tangent.Try it

Rounding & Integer Parts

11 functions

Round up, down, to nearest, truncate, or convert to integer types.

FunctionDescriptionTutorial
ceil()Round toward +infinity.Try it
floor()Round toward −infinity.Try it
round()Round to nearest integer as double.Try it
trunc()Truncate toward zero.Try it
nearbyint()Round without raising FE_INEXACT.Try it
rint()Round using the current rounding mode.Try it
lrint()Round to long.Try it
llrint()Round to long long.Try it
lround()Round half away from zero to long.Try it
llround()Round half away from zero to long long.Try it
modf()Split into whole and fraction.Try it

Min, Max & Magnitude

11 functions

Choose the smaller or larger value, including C23 numeric and magnitude helpers.

FunctionDescriptionTutorial
fmin()Smaller of two doubles.Try it
fmax()Larger of two doubles.Try it
fdim()Positive difference max(x-y, 0).Try it
fminimum()Minimum with NaN rules (C23).Try it
fmaximum()Maximum with NaN rules (C23).Try it
fminimum_num()Numeric minimum (C23).Try it
fmaximum_num()Numeric maximum (C23).Try it
fminimum_mag()Minimum magnitude (C23).Try it
fmaximum_mag()Maximum magnitude (C23).Try it
fminimum_mag_num()Numeric minimum magnitude (C23).Try it
fmaximum_mag_num()Numeric maximum magnitude (C23).Try it

Remainder, Scale & Decomposition

10 functions

Floating remainder, mantissa/exponent, scale by powers of the radix, and hypotenuse.

FunctionDescriptionTutorial
fmod()Floating-point remainder.Try it
remainder()IEEE remainder.Try it
remquo()Remainder plus quotient bits.Try it
frexp()Mantissa and exponent of x.Try it
ldexp()x times 2 raised to exp.Try it
scalbn()Scale x by FLT_RADIX**n (int).Try it
scalbln()Scale x by FLT_RADIX**n (long).Try it
hypot()sqrt(x² + y²) without overflow.Try it
fma()Fused multiply-add x*y + z.Try it
copysign()Copy the sign of y onto x.Try it

Next Representable Value

4 functions

Step to the next floating-point number in a chosen direction.

FunctionDescriptionTutorial
nextafter()Next value toward y.Try it
nexttoward()Next value toward a long double.Try it
nextup()Next value toward +infinity.Try it
nextdown()Next value toward −infinity.Try it

Classification & Comparison

13 functions

Test NaN, infinity, finiteness, and compare without the usual NaN surprises.

FunctionDescriptionTutorial
fpclassify()Classify a floating value.Try it
isfinite()True if finite.Try it
isinf()True if infinite.Try it
isnan()True if NaN.Try it
isnormal()True if normal.Try it
signbit()True if sign bit is set.Try it
isgreater()Greater-than compare.Try it
isgreaterequal()Greater-or-equal compare.Try it
isless()Less-than compare.Try it
islessequal()Less-or-equal compare.Try it
islessgreater()Not-equal compare for ordered values.Try it
isunordered()True if a compare is unordered.Try it
nan()Build a quiet NaN from text.Try it

Special Functions

4 functions

Error function, complementary error function, and gamma helpers.

FunctionDescriptionTutorial
erf()Error function.Try it
erfc()Complementary error function.Try it
tgamma()Gamma function.Try it
lgamma()Log absolute gamma.Try it

Key Takeaways

  • This page is the catalog of every math function tutorial in the C series.
  • Start with fabs, sqrt, pow, and sin (radians).
  • Choose by job above when you know the task but not the function name.
  • Lesson first: C Math for -lm and examples; this index for lookup.

One line: Use this index to find the right math.h tutorial—search, choose by job, then open the guide.

Frequently Asked Questions

They are library routines—mostly in math.h—for floating-point work: roots, powers, logs, trigonometry, rounding, and remainders. You call them by name, such as sqrt(16.0) or sin(M_PI / 2).
C Math is the lesson: include math.h, link with -lm, use radians, and work through examples. This Math Functions page is the catalog—search and open each function’s full tutorial.
If you are new, read C Math first. In this index, open fabs(), sqrt(), pow(), and sin() next. Then pick rounding or more trig from the tables below.
On GCC and Clang, yes: gcc main.c -std=c11 -o main -lm. MSVC often links math automatically. Full compile notes live on the C Math overview.
No—radians. Convert with deg * M_PI / 180.0. See the C Math lesson and the sin() tutorial for worked examples.
Syntax, return value, three examples with output, notes, and FAQs for that one function. Use this index to jump to the right guide.

Start with fabs()

Open the floating absolute-value guide—syntax, examples, and a quick reference.

fabs() tutorial →

CODETOFUN NEWS

Stay Ahead in Tech

Get the latest IT news, programming updates, and technology trends directly on your phone.

Your daily dose of tech, straight to your feed.

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.

30 people found this page helpful