C Math Functions

Beginner
⏱️ 14 min read
📚 Updated: Jul 2026
🎯 30 Tutorials
<math.h>

What You’ll Find Here

The C standard library provides powerful math functions in <math.h> for roots, powers, logarithms, trigonometry, rounding, and floating-point decomposition. This page is your central hub: browse all 30 functions in our tutorial series, jump to full guides with five examples each, and learn patterns that work in real C programs.

01

Full Tutorials

30 functions with examples.

02

Quick Reference

All functions by category.

03

Searchable

Filter by function name.

04

Link -lm

GCC/Clang compile tips.

05

Radians

Trig angle units explained.

06

Start Here

fabs() → sqrt().

Introduction

In C, you perform floating-point math through library functions in <math.h> such as sqrt(), pow(), sin(), and floor()—not operators like x^2 in some other languages. Most return double; variants like sqrtf() and sinf() work with float.

Integer absolute value abs() lives in <stdlib.h>, while fabs() handles floating-point magnitudes in <math.h>. Know which header each function needs before you compile.

💡
Beginner Tip

Compile with the math library on GCC/Clang: gcc main.c -std=c11 -o main -lm. Put -lm at the end of the command. Trig functions expect radians—convert degrees with degrees * (M_PI / 180.0).

Math Functions Index

Search by function name or browse by category. Cards marked Tutorial link to full guides with syntax, five examples, output, and FAQs.

Absolute Value

2 functions

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

Roots & Powers

3 functions

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

Exponential & Logarithm

3 functions

Natural exponent, natural log, base-10 log, and e^x growth models.

Circular Trigonometry

7 functions

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

Hyperbolic Functions

6 functions

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

Rounding & Integer Parts

5 functions

Round up, down, to nearest, truncate toward zero, or split whole and fractional parts.

Remainder & Decomposition

4 functions

Floating remainder, split into mantissa and exponent, scale by powers of two, and hypotenuse length.

🚀 Usage Tips

  • Link with -lm — on GCC/Clang: gcc file.c -std=c11 -o out -lm.
  • Use radians for trig — convert degrees: rad = deg * M_PI / 180.0.
  • Pick the right absabs() for int, fabs() for double.
  • Compare rounding functionsfloor, ceil, round, and trunc differ on negatives and halves.
  • Prefer atan2 over atanatan2(y, x) handles all quadrants for slope angles.
  • Read the tutorial — each linked page includes syntax, five examples, a quick reference table, and FAQs.

📝 How to Call a Math Function

Every math.h function follows the same general pattern:

#include <math.h>
double result = function_name(arguments);

Common Patterns

GoalExample
Square rootsqrt(25.0)5.0
Powerpow(2.0, 10.0)1024.0
Sine of 90°sin(M_PI / 2.0)1.0
Float absolute valuefabs(-3.14)3.14
Truncate decimalstrunc(3.75)3.0

math.h vs stdlib.h

Not every numeric helper lives in <math.h>. Integer abs(), labs(), and llabs() are declared in <stdlib.h>. Floating-point math—roots, trig, rounding, fabs()—comes from <math.h>.

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

int main(void) {
    int n = -42;
    double x = -3.14;

    printf("abs(%d)  = %d\n", n, abs(n));
    printf("fabs(%g) = %g\n", x, fabs(x));
    printf("sqrt(16) = %g\n", sqrt(16.0));

    return 0;
}
/* Compile: gcc demo.c -std=c11 -o demo -lm */

Conclusion

C math functions cover roots, powers, logarithms, trigonometry, hyperbolic curves, rounding, and remainders. Use this index to find the right function quickly, then open the full tutorial for syntax, examples, and best practices.

New to C math? Read the C Math overview first, then start with fabs() and sqrt() before diving into sin() and pow().

❓ Frequently Asked Questions

C math functions are library routines in math.h for floating-point arithmetic: roots, powers, logarithms, trigonometry, rounding, and remainder operations. You call them by name with numeric arguments, such as sqrt(16.0) or sin(M_PI / 2).
Include #include <math.h>, call the function, and link with -lm on many systems: gcc main.c -std=c11 -o main -lm. Example: double r = sqrt(25.0); printf("%f\n", r);
On GCC and Clang (Linux, macOS, MinGW), yes—math functions are in a separate library. MSVC often links math automatically. If you see undefined reference to sqrt, add -lm at the end of your gcc command.
Radians. Convert degrees first: double rad = degrees * (M_PI / 180.0); then call sin(rad). On MSVC define _USE_MATH_DEFINES before math.h for M_PI.
abs() is for integers (stdlib.h). fabs() is floating-point absolute value (math.h). floor() rounds toward negative infinity to an integer-valued double—not the same as absolute value.
Start with fabs() and sqrt() for basics, then pow() and round() for everyday math. When you need angles, learn sin() and cos() with radian conversion. Open the tutorials below for syntax, five examples, and FAQs per function.
Did you know?

Tip: Most C math functions live in <math.h> and return double—for example sqrt(x) or sin(angle_rad). On GCC and Clang you often must link with -lm: gcc program.c -o program -lm. Circular trig functions take radians, not degrees.

Start Your First Math Function Tutorial

Open the fabs() guide—syntax, five examples, and a quick reference cheat sheet.

fabs() 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.

30 people found this page helpful