Task

Calculate the value of   e.



(e   is also known as   Euler's number   and   Napier's constant.)



See details: Calculating the value of e

func calculateE(epsilon = 1.0e-15) {
    func abs(n) {
        if n < 0 {
            -n
        } else {
            n
        }
    }
 
    var fact = 1
    var e = 2.0
    var e0 = 0.0
    var n = 2
 
    while true {
        e0 = e
        fact *= n
        n += 1
        e += 1.0 / Float(fact)
 
        if abs(e - e0) < epsilon {
            break
        }
    }
 
    return e
}
 
print(calculateE())