Ruby - Math.cbrt() Method
The Ruby Math.cbrt() method returns the cube root of the given number.
Syntax
Math.cbrt(x)
Parameters
x |
Specify the number. |
Return Value
Returns the cube root of the specified number.
Example:
In the example below, Math.cbrt() method is used to find out the cube root of the given number.
puts "Math.cbrt(27) = #{Math.cbrt(27)}" puts "Math.cbrt(64) = #{Math.cbrt(64)}" puts "Math.cbrt(100) = #{Math.cbrt(100)}" puts "Math.cbrt(-27) = #{Math.cbrt(-27)}"
The output of the above code will be:
Math.cbrt(27) = 3.0 Math.cbrt(64) = 4.0 Math.cbrt(100) = 4.641588833612779 Math.cbrt(-27) = -3.0
❮ Ruby Math Module