The cbrt() function computes the cube root of a number—the value that multiplied by itself three times gives the original. It is the natural companion to sqrt() when you work with volumes, 3D scaling, or engineering formulas involving cubic relationships.
01
Cube root
∝x.
02
math.h
Link with -lm.
03
Negatives
Works fine.
04
vs sqrt
3rd power.
05
vs pow
Prefer cbrt.
06
Volume
Edge length.
Fundamentals
Definition and Usage
The cube root of x is the number y such that y × y × y = x, written mathematically as x1/3.
In C, cbrt(x) computes this directly. Unlike pow(x, 1.0/3.0), it handles negative inputs correctly—cbrt(-8) is −2, not NaN.
💡
Beginner Tip
If you know a cube’s volume, cbrt(volume) gives the side length. Volume 125 cm³ → edge 5 cm.
For a cube, volume = side³, so side = cbrt(volume). The same idea applies to uniform 3D scaling in graphics.
Example 5 — cbrt() vs pow(x, 1.0/3.0)
See why cbrt is better for negative numbers.
C
#include <math.h>
#include <stdio.h>
int main(void) {
double x = -27.0;
double via_cbrt = cbrt(x);
double via_pow = pow(x, 1.0 / 3.0);
printf("x = %.0f\n", x);
printf("cbrt(x) = %.4f\n", via_cbrt);
printf("pow(x, 1.0/3.0) = %.4f", via_pow);
if (isnan(via_pow))
printf(" (NaN on many systems)\n");
else
printf("\n");
return 0;
}
📤 Output:
x = -27
cbrt(x) = -3.0000
pow(x, 1.0/3.0) = nan (NaN on many systems)
How It Works
pow with a non-integer exponent often fails on negative bases. cbrt is the portable, correct tool for cube roots of any real number.
Applications
🚀 Common Use Cases
Geometry — find cube edge length from volume.
Engineering — stress and material formulas with cubic terms.
3D graphics — uniform scale factor from volume ratios.
Physics — equations where quantities scale with the cube of a linear dimension.
Numeric algorithms — prefer cbrt over pow for accuracy.
🧠 How cbrt() Works
1
Accept any real x
Positive, negative, or zero.
Input
2
Compute ∝x
Library uses an accurate cube-root algorithm.
Compute
3
Preserve sign
Negative input → negative cube root.
Sign
=
📐
Cube root
y where y³ ≈ x.
Important
📝 Notes
Declared in <math.h> (C99 and later).
Works correctly for negative x—unlike pow(x, 1.0/3.0).
Link with -lm when using GCC/Clang on Unix-like systems.
Use cbrtf or cbrtl for float or long double data.
For square roots, use sqrt(); for general powers, use pow().
Performance
⚡ Optimization
cbrt() is implemented in the platform math library and is already optimized. Prefer it over pow(x, 1.0/3.0) for clarity, correctness on negatives, and typically better precision. Cache results when the same value is computed repeatedly in a loop.
Wrap Up
Conclusion
cbrt() is the standard way to compute cube roots in C. Include <math.h>, link -lm, and prefer it over fractional pow especially when x may be negative.
Continue with ceil() for rounding up, or explore sqrt() for square roots.
sqrt() computes square roots (√x, exponent ½). cbrt() computes cube roots (∛x, exponent ⅓). Use sqrt for areas; cbrt for volumes scaled to edge length.
Prefer cbrt(x). It is clearer, handles negative x correctly, and is typically more accurate than raising to the floating-point fraction 1/3.
cbrt(0) returns 0. The cube root of zero is zero.
Did you know?
The cbrt function was added to C in the C99 standard alongside other root and rounding helpers. Before C99, programmers often used pow(x, 1.0/3.0)—which still fails on negative x today.