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

 
# syntax: GAWK -f CALCULATING_THE_VALUE_OF_E.AWK
BEGIN {
    epsilon = 1.0e-15
    fact = 1
    e = 2.0
    n = 2
    do {
      e0 = e
      fact *= n++
      e += 1.0 / fact
    } while (abs(e-e0) >= epsilon)
    printf("e=%.15f\n",e)
    exit(0)
}
function abs(x) { if (x >= 0) { return x } else { return -x } }
 