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

0 var e0 2 var e 0 var n 1 var fact
1e-15 var v
 
def printOp
    swap print print nl
enddef
 
def test e e0 - abs v >= enddef
 
test
while
    e var e0
    n 1 + var n
    2 n * 2 n * 1 + * fact * var fact
    2 n * 2 + fact / e + var e
    test
endwhile
 
2.718281828459045 var rE
 
"Computed e = " e tostr printOp
"Real e = " rE tostr printOp
"Error = " rE e - printOp
"Number of iterations = " n printOp