C Math cbrt() Function

Beginner
⏱️ 8 min read
📚 Updated: Jul 2026
🎯 5 Examples
<math.h>

What You’ll Learn

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.

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.

📝 Syntax

Standard C declaration:

C
double cbrt(double x);

Related variants

C
float cbrtf(float x);           /* <math.h> */
long double cbrtl(long double x); /* <math.h> */

Parameters

  • x — any real number (positive, negative, or zero).

Return Value

  • Cube root of x as a double.
  • cbrt(0) returns 0.
  • Sign of result matches sign of x (for negative x).

Headers and linking

  • #include <math.h>
  • Compile: gcc cbrt.c -std=c11 -o cbrt -lm

⚡ Quick Reference

CallMeaningResult
cbrt(27)3³ = 273
cbrt(8)2³ = 82
cbrt(-8)(−2)³ = −8-2
cbrt(0)0³ = 00
cbrt(r)*cbrt(r)*cbrt(r)Verify
Cube root
cbrt(x)

Direct

Square root
sqrt(x)

2nd power

Avoid
pow(x, 1.0/3)

Negatives

Volume
cbrt(volume)

Edge length

Examples Gallery

Compile every example with gcc file.c -std=c11 -o out -lm. Cube roots appear in geometry, physics, and graphics scaling.

📚 Getting Started

Compute the cube root of a perfect cube.

Example 1 — Basic Cube Root

Find the cube root of 27.

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

int main(void) {
    double number = 27.0;
    double result = cbrt(number);

    printf("Cube root of %.0f is %.2f\n", number, result);

    return 0;
}

How It Works

cbrt(27) returns 3 because 3 × 3 × 3 = 27. This matches the reference example.

Example 2 — Cube Root of a Negative Number

Unlike fractional pow, cbrt handles negatives.

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

int main(void) {
    double x = -8.0;

    printf("cbrt(%.0f) = %.2f\n", x, cbrt(x));

    return 0;
}

How It Works

cbrt(-8) = -2 because (−2)³ = −8. The result keeps the sign of the input—not just the cube root of the absolute value as a separate step.

📈 Practical Patterns

Verification, real-world volume, and comparison with pow.

Example 3 — Verify by Cubing the Result

Multiply the cube root three times to recover the original.

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

int main(void) {
    double values[] = { 64.0, 10.0, -27.0 };
    size_t i;

    for (i = 0; i < 3; i++) {
        double x = values[i];
        double r = cbrt(x);
        double back = r * r * r;

        printf("x=%6.1f  cbrt(x)=%.4f  r^3=%.4f\n", x, r, back);
    }

    return 0;
}

How It Works

Cubing cbrt(x) should return x (within floating-point tolerance). This is a quick sanity check for any cube-root calculation.

Example 4 — Cube Volume to Edge Length

A box holds 125 cm³—what is the side length?

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

int main(void) {
    double volume_cm3 = 125.0;
    double edge_cm = cbrt(volume_cm3);

    printf("Volume = %.0f cm^3\n", volume_cm3);
    printf("Edge length = %.1f cm\n", edge_cm);

    return 0;
}

How It Works

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;
}

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.

🚀 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.

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

⚡ 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.

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.

💡 Best Practices

✅ Do

  • Include <math.h> and link with -lm
  • Use cbrt(x) instead of pow(x, 1.0/3.0)
  • Verify with r*r*r while learning
  • Use cbrtf for single-precision pipelines
  • Apply to volume-to-edge geometry problems

❌ Don’t

  • Use pow for negative cube roots
  • Confuse cbrt with sqrt
  • Forget -lm on Linux builds
  • Expect exact integers for non-perfect cubes
  • Hand-roll Newton’s method unless you need to

Key Takeaways

Knowledge Unlocked

Five things to remember about cbrt()

Cube roots in C, explained simply.

5
Core concepts
📚 02

math.h

Link -lm.

Setup
03

Negatives OK

cbrt(-8)=-2.

Domain
📈 04

vs pow

Prefer cbrt.

Compare
📦 05

Volume

Edge length.

Pattern

❓ Frequently Asked Questions

cbrt() returns the cube root of x—the value that, when multiplied by itself three times, gives x. For example, cbrt(27) is 3 because 3 × 3 × 3 = 27.
Include <math.h> and link with -lm on many systems: gcc program.c -o program -lm. The function is declared as double cbrt(double x).
Yes. Unlike pow(x, 1.0/3.0), cbrt handles negatives correctly. cbrt(-8) returns -2 because (-2)³ = -8.
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.

Explore C Math Functions

Continue with ceil() or browse the full math function reference.

Math Functions Index →

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.

5 people found this page helpful