What is Math.cbrt() in Ruby?

The cbrt() function in Ruby returns the cube root of a number.

Figure 1 below shows the mathematical representation of the cbrt() function.

The Math module is required to use this function.

Figure 1: Mathematical representation of the cbrt() function

Syntax

cbrt(number)

Parameter

cbrt() requires a number as a parameter.

Return value

cbrt() returns the cube root of the number sent as a parameter.

Code

The following example shows how to use cbrt() in Ruby.

print "cbrt(8):", Math.cbrt(8), "\n"
print "cbrt(0):", Math.cbrt(0), "\n"
print "cbrt(-25):", Math.cbrt(-25), "\n"
print "cbrt(4.5):", Math.cbrt(4.5), "\n"