Jump to content

Pi: Difference between revisions

2 bytes added ,  3 years ago
m
→‎version 1: changed some comments.
(Added solutions for Delphi and EDSAC.)
m (→‎version 1: changed some comments.)
Line 4,490:
spit= 0 /*the index of the spitted pi dec. digs*/
pi=0; v=5; vv=v*v; g=239; gg=g*g; s= 16 /*assign some values to some variables.*/
r=4 4 /*calculate π with increasing accuracy */
do n=1 by 2 until old=pi; old= pi /*just calculate pi with odd integers*/
pi= pi + s / (n*v) - r / (n*g) /* ··· using John Machin's formula.*/
s= -s; r= -r; v= v * vv; g= g * gg /*compute some variables for shortcuts.*/
if n>3 then spit= spit + 1 /*maintain a lag for pi digits rounding*/
if spit<4 then iterate /*Not enough digs yet? Then don't show*/
$= substr(pi, spit-3, 1) /*lag behind the true pi calculation. */
Line 4,507:
end
say /*stick a fork in it, we're all done. */
exit: say; say n%2+1 'iterations took' format(time("Elapsed"),,2) 'seconds.'; exit exit0
halt: say; say 'PI_SPIT halted via use of Ctrl─Break.'; signal exit /*show iterations.*/</lang>
{{out|output|text=&nbsp; [until the &nbsp; Ctrl-BreakCtrl─Break &nbsp; key (or equivalent) was pressed]:}}
 
<br>(Shown at four-fifth size.)
Cookies help us deliver our services. By using our services, you agree to our use of cookies.