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

1000 sn                 [ n = number of iterations ]sx
2574k                   [ precision to use during computation ]sx
1 d se sf               [ set e and f to 1 ]sx
0 si                    [ set i to 0 ]sx
[                       [ p = begin ]sx
  lf li 1 + d si * sf     [ f = f*(++i) ]sx
  le 1 lf / + se          [ e = e + 1/f ]sx
  ln li <p                [ if i<n recur ]sx
]sp                     [ end ]sx
 
lpx                     [ call p ]sx
 
[After ]n lnn           [ output header. uses n + 10P for newline ]sx
[ iterations, e =]n     [ instead of p, so nothing is left hanging ]sx
10P                     [ around on the stack.]sx
 
2570k                   [ now reset precision to match correct digits ]sx
le 1 /                  [ get result truncated to that precision ]sx
n 10P                   [ and print it out, again with n + 10P ]sx