Jump to content

Calculating the value of e: Difference between revisions

→‎dc: calculate reciprocal factorial directly, avoiding division by large numbers, ~100 x faster with GNU dc
(→‎AWK: simplify)
(→‎dc: calculate reciprocal factorial directly, avoiding division by large numbers, ~100 x faster with GNU dc)
Line 926:
<syntaxhighlight lang="dc">1000 sn [ n = number of iterations ]sx
2574k [ precision to use during computation ]sx
1 d se sf [ set e (kept on the stack) and f to 1 ]sx
0 si [ set i to 0 ]sx
[ [ p = begin ]sx
lf li 1 + d si */ d 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
Line 941 ⟶ 940:
 
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</syntaxhighlight>
{{Outout}}
 
{{Out}}
<pre>After 1000 iterations, e =
2.7182818284590452353602874713526624977572470936999595749669676277240\
Line 984 ⟶ 982:
574540161372236187893652605381558415871869255386061647798340254351284\
3961294603529133259</pre>
 
=={{header|Delphi}}==
''See [[#Pascal|Pascal]]''
559

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.