C Math Functions

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—30 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).
Compile tips, radians, and five worked examples are on C Math—not repeated here.
Convert first: rad = deg * M_PI / 180.0 before sin / cos / tan.
C Syntax
Every math.h call follows the same pattern—include, call, link:
#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:
| Job | Prefer |
|---|---|
| Distance / radius | sqrt() or hypot() |
| Powers / growth | pow(), exp() |
| Angles | sin(), cos() after degree→radian |
| Quadrant-aware angle | atan2() instead of atan() |
| Snap / grids | floor(), ceil(), trunc() |
| Float compare tolerance | fabs(a - b) < epsilon with fabs() |
| Integer magnitude | abs() from <stdlib.h> |
Quick results cheat sheet
| Call | Result |
|---|---|
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:
- If you still need
-lmor radians, open the C Math lesson first. - Use Choose a Function by Job when you know the task but not the name.
- Use the search box below when you already know the function name.
- Browse categories when you want related APIs (for example all rounding helpers).
- Open a tutorial for syntax, five examples, output, and FAQs—then return here for the next one.
C Math Functions Index
30 tutorials. Search by name or scroll the categories. Each row opens a full guide.
Absolute Value
2 functionsRemove the sign—integer abs() in stdlib.h and floating-point fabs() in math.h.
Roots & Powers
3 functionsSquare roots, cube roots, and raise a number to any exponent.
Exponential & Logarithm
3 functionsNatural exponent, natural log, and base-10 log.
Circular Trigonometry
7 functionsSine, cosine, tangent, and inverses—angles in radians unless you convert from degrees.
| Function | Description | Tutorial |
|---|---|---|
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 functionssinh, cosh, tanh and inverses—not the same as circular trig despite similar names.
Rounding & Integer Parts
5 functionsRound up, down, to nearest, truncate toward zero, or split whole and fractional parts.
Remainder & Decomposition
4 functionsFloating remainder, mantissa/exponent, scale by powers of two, and hypotenuse length.
Key Takeaways
- This page is the catalog of every math function tutorial in the C series.
- Start with
fabs,sqrt,pow, andsin(radians). - Choose by job above when you know the task but not the function name.
- Lesson first: C Math for
-lmand 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
Start with fabs()
Open the floating absolute-value guide—syntax, examples, and a quick reference.
30 people found this page helpful
