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—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).
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, 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 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
9 functionsNatural exponent, logs, and accurate helpers for small values.
| Function | Description | Tutorial |
|---|---|---|
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 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
11 functionsRound up, down, to nearest, truncate, or convert to integer types.
| Function | Description | Tutorial |
|---|---|---|
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 functionsChoose the smaller or larger value, including C23 numeric and magnitude helpers.
| Function | Description | Tutorial |
|---|---|---|
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 functionsFloating remainder, mantissa/exponent, scale by powers of the radix, and hypotenuse.
| Function | Description | Tutorial |
|---|---|---|
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 functionsStep to the next floating-point number in a chosen direction.
| Function | Description | Tutorial |
|---|---|---|
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 functionsTest NaN, infinity, finiteness, and compare without the usual NaN surprises.
| Function | Description | Tutorial |
|---|---|---|
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 functionsError function, complementary error function, and gamma helpers.
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.
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.
30 people found this page helpful
