Open In App

Ruby CMath cbrt() Method with example

Last Updated : 07 Jan, 2020
Improve
Improve
Like Article
Like
Save
Share
Report

cbrt method is a Math class method in Ruby which is used to calculate the cube root of the given value.

Syntax: Math.cbrt(z)

Parameter: Here, z is the value whose cube root is to be calculated.

Returns: This method returns the cube root of the given number.

Below programs illustrate the use of above-discussed method:

Example 1:




# Ruby code for cbrt() method
require 'cmath'
  
# Initializing value
a = 27
b = 5.45
  
# Printing result  
puts "Cube root value of a : #{CMath.cbrt(a)}\n\n" 
puts "cube root value of b : #{CMath.cbrt(b)}\n\n"


Output:

Cube root value of a : 3.0

cube root value of b : 1.7598088635408027

Example 2:




# Ruby code for cbrt() method
require 'cmath'
  
# Initializing values 
a = 78
b = 729
  
# Printing result  
puts "Cube root value of a : #{CMath.cbrt(a)}\n\n" 
puts "cube root value of b : #{CMath.cbrt(b)}\n\n"


Output:

Cube root value of a : 4.272658681697917

cube root value of b : 8.999999999999998

Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads