Time for an 2014 update…
This commit is contained in:
parent
372c577f83
commit
09687c4926
2520 changed files with 34227 additions and 7318 deletions
|
|
@ -1,24 +1,22 @@
|
|||
/*REXX program to spit out pi digits (few at a time) until Ctrl-Break. */
|
||||
|
||||
arg digs .; if digs=='' then digs=1e6 /*allow the specification of digs*/
|
||||
fn='PI_DIGITS.OUT' /*file that can be written to. */
|
||||
/*REXX program spits out digits of pi (one at a time) until Ctrl-Break.*/
|
||||
arg digs .; if digs=='' then digs=1e6 /*allow the specification of digs*/
|
||||
fn = 'PI_DIGITS.OUT' /*file used for output: PI digits*/
|
||||
numeric digits digs /*big digs, the slower the spits.*/
|
||||
pi=0; s=16; r=4; v=5; vs=v*v; g=239; gs=g*g; old=; spewed=0; j=1
|
||||
call time 'E'
|
||||
|
||||
/*─────────────────────────────────────John Machin's formula for pi. */
|
||||
do n=1 by 2
|
||||
pi=pi + s/(n*v) - r/(n*g)
|
||||
if pi==old then leave /*no further with current DIGITS.*/
|
||||
s=-s; r=-r; v=v*vs; g=g*gs
|
||||
if n\==1 then do j=spewed+1 to compare(pi,old)
|
||||
spit=substr(pi,j,1)
|
||||
call charout ,spit /*spit out 1 digit of pi.*/
|
||||
call charout fn,spit /* ...and also to a file.*/
|
||||
end
|
||||
spewed=j-1
|
||||
old=pi
|
||||
pi=0; s=16; r=4; v=5; vs=v*v; g=239; gg=g*g; j=1; spit=0; old=
|
||||
call time 'Reset' /*reset the REXX wall-clock timer*/
|
||||
/*───calculate PI with increasing*/
|
||||
do n=1 by 2 /*───accuracy (up to DIGS digits)*/
|
||||
pi=pi + s/(n*v) - r/(n*g) /*───using John Machin's formula.*/
|
||||
if pi==old then leave /*have exceeded DIGITS accuracy. */
|
||||
s=-s; r=-r; v=v*vs; g=g*gg /*set some variable for shortcuts*/
|
||||
if n\==1 then do j=spit+1 to compare(pi,old) /*spit out some π digs.*/
|
||||
spit=substr(pi,j,1) /*obtain a digit of π to spit out*/
|
||||
call charout ,spit /*spit out one (new) digit of pi.*/
|
||||
call charout fn,spit /* ···and also echo it to a file.*/
|
||||
end /*j*/
|
||||
spit=j-1 /*adjust for DO index increment.*/
|
||||
old=pi /*use the "OLD" value next time. */
|
||||
end /*n*/
|
||||
|
||||
say; say n%2+1 'iterations took' format(time("E"),,2) 'seconds.'
|
||||
say; say n%2+1 'iterations took' format(time("Elapsed"),,2) 'seconds.'
|
||||
/*stick a fork in it, we're done.*/
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue