The cbrt()
function returns the cube root of a number sent as a parameter.
Figure 1 below shows the mathematical representation of the cbrt()
function.
The following module is required for this function.
import scala.math._
Double cbrt(Double number)
This function requires a number as a parameter.
cbrt()
returns the cube root of a number sent as a parameter.
- If the parameter value is
PositiveInfinity
, then it returns positive infinity.- If the parameter value is
NegativeInfinity
, then it returns negative infinity.- If the parameter value is
NaN
, then it returnsNaN
.
import scala.math._object Main extends App {//positive numberprintln(s"The value of cbrt(10) = ${cbrt(10)}");println(s"The value of cbrt(0) = ${cbrt(0)}");println(s"The value of cbrt(9) = ${cbrt(9)}");//negative numberprintln(s"The value of cbrt(-9) = ${cbrt(-9)}");//error outputsprintln(s"The value of cbrt(Double.PositiveInfinity) = ${cbrt(Double.PositiveInfinity)}");println(s"The value of cbrt(Double.NegativeInfinity) = ${cbrt(Double.NegativeInfinity)}");println(s"The value of cbrt(Double.NaN) = ${cbrt(Double.NaN)}");}