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.
cbrt(number)
cbrt()
requires a number as a parameter.
cbrt()
returns the cube root of the number sent as a parameter.
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"