![]() |
VOOZH | about |
The Math.cbrt() is a part of java.lang.Math package. This method is used to calculate the cube root of a given number. In this article, we are going to discuss how this method works for regular values and for special cases such as infinity and NaN.
Note: A number, when multiplied by itself three times, gives the original number, is known as a cube root of that number. For example, the cube root of 27 is 3 because 3 × 3 × 3 = 27.
Special Cases:
These special cases make sure that the Math.cbrt() methods work correctly.
public static double cbrt(double a)
Now, we are going to discuss some examples for better understanding.
Example 1: In this example, we will see the basic usage of cbrt() method with regular values.
5.0 Infinity -Infinity 0.0 -0.0
Explanation: Here, we are calculating the cube roots of different numbers like the cube root of 125.0 is 5.0 and for positive infinity, the cube root is positive infinity and for negative infinity, the cube root is negative infinity and for both the positive and negative zero the cube root will always be zero.
Example 2: In this example, we will see howcbrt() method handles NaN and Infinity.
Cube root of Positive Infinity: Infinity Cube root of Negative Infinity: -Infinity Cube root of NaN: NaN
Explanation: Here, we are calculating the cube roots of special values like positive infinity, negative infinity and NaN. The cube root of postitive infinity is positive infinity, the cube root of negative infinity is negative infinity and the cube root for NaN is NaN.
Important Points: