The pow()
function calculates the value of the
Figure 1 shows the mathematical representation of the pow()
function.
The following module is required for this function:
import scala.math._
Double pow(Double baseNumber, Double exponent)
The pow()
function requires two parameters:
pow()
returns the value of the base number raised to the exponent number.
- If the parameter value of the base, exponent, or both is positive infinity, then it returns positive infinity.
- If the parameter value of the base, exponent, or both is negative infinity, then it returns zero.
- If the parameter value of the base, exponent, or both is NaN, then it returns NaN.
import scala.math._object Main extends App {//positive: baseNumber positive: exponentprintln(s"The value of pow(2,3) = ${pow(2,3)}");//positive: baseNumber negative: exponentprintln(s"The value of pow(0.25,-2) = ${pow(0.25,-2)}");//negative: baseNumber positive: exponentprintln(s"The value of pow(-10,2) = ${pow(-10,2)}");//negative: baseNumber negative: exponentprintln(s"The value of pow(-0.5,-1) = ${pow(-0.5,-1)}");//error ouputprintln(s"The value of pow(Double.PositiveInfinity,Double.PositiveInfinity) = ${pow(Double.PositiveInfinity,Double.PositiveInfinity)}");println(s"The value of pow(Double.NegativeInfinity,Double.NegativeInfinity) = ${pow(Double.NegativeInfinity,Double.NegativeInfinity)}");println(s"The value of pow(Double.NaN,Double.NaN) = ${pow(Double.NaN,Double.NaN)}");}