The pow()
function calculates the value of a
The figure below shows the mathematical representation of the pow()
function:
Note: We need to import
Foundation
in our code to use thepow()
function. We can import it like this:import Foundation
.
Let's view the syntax of the function:
pow(baseNumber, exponent)
The pow()
function requires two parameters:
The pow()
returns the value of the base number raised to the exponent number.
The code below shows the use of the pow()
function in Swift:
import Swiftimport Foundation//positive: baseNumber positive: exponentprint ("The value of pow(2.0,3.0) : ",pow(2.0,3.0));//positive: baseNumber negative: exponentprint ("The value of pow(0.25,-2.0) : ",pow(0.25,-2.0));//negative: baseNumber positive: exponentprint ("The value of pow(-10.0,2.0) : ",pow(-10.0,2.0));//negative: baseNumber negative: exponentprint ("The value of pow(-0.5,-1.0) : ",pow(-0.5,-1.0));
Foundation
header required for the pow()
function.pow()
.pow()
.pow()
.pow()
.