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