C# Cbrt()

Anonymous contributor's avatar
Anonymous contributor
Published Nov 15, 2025
Contribute to Docs

The Math.Cbrt() method in C# returns the cube root of a given number. It handles positive, negative, and special floating-point values such as NaN and infinities.

  • Looking for an introduction to the theory behind programming? Master Python while learning data structures, algorithms, and more!
    • Includes 6 Courses
    • With Professional Certification
    • Beginner Friendly.
      75 hours
  • Learn Microsoft's popular C# programming language, used to make websites, mobile apps, video games, VR, and more.
    • Beginner Friendly.
      15 hours

Syntax

Math.Cbrt(double x)

Parameters:

  • x (double): The number whose cube root is to be calculated.

Return value:

The method will return a value of type double unless the value passed is one of the following:

  • If x is NaN, the method will return NaN.
  • If x is PositiveInfinity, the method will return PositiveInfinity.
  • If x is NegativeInfinity, the method will return NegativeInfinity.
  • If x is negative, the method will return the real cube root (a negative number).

Example

In this example, different numeric values are passed to Math.Cbrt() to calculate their cube roots:

using System;
namespace MyCubeRoot {
public class Example {
public static void Main(string[] args) {
double a = Math.Cbrt(27);
double b = Math.Cbrt(-8);
double c = Math.Cbrt(1000);
double d = Math.Cbrt(0.125);
Console.WriteLine(a);
Console.WriteLine(b);
Console.WriteLine(c);
Console.WriteLine(d);
}
}
}

This example results in the following output:

3.0000000000000004
-2
10
0.49999999999999994

Codebyte Example

In this example, the cube root of 64 is calculated using Math.Cbrt() and printed to the console:

Code
Output
Loading...

All contributors

Contribute to Docs

Learn C# on Codecademy

  • Looking for an introduction to the theory behind programming? Master Python while learning data structures, algorithms, and more!
    • Includes 6 Courses
    • With Professional Certification
    • Beginner Friendly.
      75 hours
  • Learn Microsoft's popular C# programming language, used to make websites, mobile apps, video games, VR, and more.
    • Beginner Friendly.
      15 hours