Java Math cbrt()

Overview
Java cbrt() method defined in the Math class calculates the cube root of a double value.
- Java cbrt() method returns NaN if the input argument is NaN.
- Java cbrt() method returns Infinity if the argument is infinite with the same sign as the argument.
- Java cbrt() method returns zero if the argument is zero with the same sign as the argument.
Build an AI-First Career, Master the Complete Skillset
Choose from our industry-leading programs designed for career success
Modern Software and AI Engineering Program
Master full-stack development with AI integration
+1000 moreModern Data Science and ML with specialisation in AI
Advanced data science techniques with AI specialization
+1000 moreAdvanced AIML with Specialisation in Agentic AI
Deep dive into AIML with focus on Agentic systems
+1000 moreDevOps, Cloud & AI Platform Engineering
Build and manage AI-powered cloud infrastructure
+1000 moreAI Engineering Advanced Certification by IIT-Roorkee
Premier AI engineering certification from IIT-Roorkee
AI Forward Deployed Engineer Program
Full-stack engineering, production AI and client-facing consulting
+1000 moreSyntax of Math cbrt() in Java
The syntax of cbrt() method is given below.
The Java cbrt() method is a static method of Math class.
Parameters of Math cbrt() in Java
The cbrt() method takes only single parameter.
- num: A numeric value of double type whose cube root is to be computed.
Return Value of Math cbrt() in Java
- The cbrt() method returns NaN if passed value is NaN.
- The cbrt() method returns zero if number passed is zero with the same sign.
- If the argument is Infinite then cbrt() will return Infinity with same sign.
- Return type is double
Note: If the number passed as argument is a negative number then cbrt() method will return a negative number. cbrt(-num) = -cbrt(num).
Exceptions of Math cbrt() in Java
cbrt() method does NOT throw any exception.
How Scaler Transformed Careers in Different Fields
Scaler learners achieved 2.5x salary growth with average post-Scaler CTC reaching ₹23L.
Example
In this sample code, we are going to see how to use cbrt() method in java.
Output
Code Explanation
- In the above code, we have used cbrt() method to find the cube root of 27 and -125.
- As the cube root of 27 is 3 so it will return 3.0.
- And as we discussed above, cube root of a negative number will be negative so cbrt() will return -5.0 as a cube root of -125.
What is Math cbrt() in Java?
The cube root of a numeric value can be computed using the cbrt() method in Java.
Turn Learning into Career Growth
More Examples
Example 1
Finding Cube root of Positive Infinity
Output:
Explanation:
- As we discussed above if argument is infinite then it will return Infinity with same sign as argument.
Example 2
In this example we are going to find cube root of zero with positive and negative signs.
Output:
Explanation:
- As discussed above, if the argument is zero, the return value of cbrt() method is also zero with the same sign.
Example 3
In this example we are going see the return value of Java cbrt() method when the argument is NaN.
Output:
Explanation:
- As discussed above, if the argument is NaN, the return value of Java cbrt() method is also NaN.
Conclusion
- Math.cbrt() method is used to find the cube root of given number.
- Java cbrt() method returns NaN if the input argument is NaN.
- Java cbrt() method returns Infinity if the argument is infinite with the same sign as the argument.
- Java cbrt() method returns zero if the argument is zero with the same sign as the argument.