📜  Ruby CMath cbrt() 方法与示例

📅  最后修改于: 2022-05-13 01:55:34.809000             🧑  作者: Mango

Ruby CMath cbrt() 方法与示例

cbrt 方法是 Ruby 中的 Math 类方法,用于计算给定值的立方根。

下面的程序说明了上述方法的使用:

示例 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"

输出:

Cube root value of a : 3.0

cube root value of b : 1.7598088635408027

示例 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"

输出:

Cube root value of a : 4.272658681697917

cube root value of b : 8.999999999999998