The log()
function in Swift calculates the natural logarithm of a number. We can find it in Swift's Foundation
library.
The mathematical representation of the log()
function is as follows:
The syntax for the log()
function is as follows:
log(number)// The number should be floating, double, or real.
This function requires a number for which the logarithm is to be calculated. It must be greater than 0.
log()
returns the natural logarithm of the number sent as a parameter.
The code below shows the use of the log()
function in Swift.
import Swiftimport Foundation// Positive integerprint ("The value of log(4.0) : ", log(4.0));//Positive double valueprint ("The value of log(4.4) : ",log(4.4));//Eprint ("The value of log(M_E) : ",log(M_E));//Exceptional outputprint ("The value of log(-4.5) : ",log(-4.5));print ("The value of log(0.0) : ",log(0.0));
Foundation
header required for the log()
function.log()
.log()
.log()
.log()
.