Data update

This commit is contained in:
Ingy döt Net 2026-02-01 16:33:20 -08:00
parent 5150844a7d
commit 4bb20c9b71
7735 changed files with 38060 additions and 199180 deletions

View file

@ -1,29 +1,36 @@
/*REXX program spits out decimal digits of pi (one digit at a time) until Ctrl─Break.*/
parse arg digs oFID . /*obtain optional argument from the CL.*/
if digs=='' | digs=="," then digs= 1e6 /*Not specified? Then use the default.*/
if oFID=='' | oFID=="," then oFID='PI_SPIT.OUT' /* " " " " " " */
write= digs<0 /*if ODIGS is <0, also spit pi to file.*/
numeric digits abs(digs) + 4 /*with bigger digs, spitting is slower.*/
call time 'Reset' /*reset the wall─clock (elapsed) timer.*/
signal on halt /*───► HALT when Ctrl─Break is pressed.*/
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 /*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. */
call charout , $ /*write the spitted digits to the term.*/
if write then call charout oFID, $ /* " " " " " a file?*/
end /*n*/
-- 12 Sep 2025
include Setting
signal on halt
arg digs
if digs = '' then
digs=1000
$= substr(pi, spit - 2); L= length($) - 4 /*handle any residual decimal digits. */
if L>0 then do /*if any residual digits, then show 'em*/
call charout , substr($, 1, L) /*write to term. */
if write then call charout oFID, substr($, 1, L) /* " " file? */
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 0
halt: say; say 'PI_SPIT halted via use of CtrlBreak.'; signal exit /*show iterations.*/
say 'PI - Machin formula'
say version
say
numeric digits digs+4
spit=0; pie=0; v=5; vv=v*v; g=239; gg=g*g; s=16; r=4
do n = 1 by 2 until old = pie
old=pie; pie=pie+s/(n*v)-r/(n*g)
s=-s; r=-r; v=v*vv; g=g*gg
if n > 3 then
spit=spit+1
if spit < 4 then
iterate
dd=SubStr(pie,spit-3,1); call CharOut ,dd
end
dd=SubStr(pie,spit-2); l=Length(dd)-4
if l>0 then
call CharOut ,SubStr(dd,1,l)
say
say 'Specified' digs 'digits exhausted.'
call Timer
exit
Halt:
say
say 'Halted because of Ctrl-Break.'
call Timer
exit
include Math

View file

@ -1,32 +1,40 @@
/*REXX program spits out decimal digits of pi (one digit at a time) until Ctrl-Break.*/
signal on halt /*───► HALT when Ctrl─Break is pressed.*/
parse arg digs oFID . /*obtain optional argument from the CL.*/
if digs=='' | digs=="," then digs= 300 /*Not specified? Then use the default.*/
if oFID=='' | oFID=="," then oFID='PI_SPIT2.OUT' /* " " " " " " */
numeric digits digs /*with bigger digs, spitting is slower.*/
q=1; r=0; t=1; k=1; n=3; L=3; z=0 /*define some REXX variables. */
dot=1 /*DOT≡a flag when a dot in pi is shown.*/
do until z==digs; qq= q+q /* qq is a fast version of: q*2 */
tn= t*n /* t*n is used twice (below). */
if qq+qq+r-t < tn then do; z= z+1 /* qq+qq is faster than qq*2 */
call charout , n
call charout oFID, n
if dot then do; dot=0; call charout , .
call charout oFID, .
end
nr= (r - tn) * 10
n = ((( (qq+q+r) * 10) / t) - n*10) %1
q = q*10
end
else do; nr= (qq+r) * L
tL= t*L
n = (q * (k*7 + 2) + r*L) / tL %1
q = q*k
t = tL
L = L+2
k = k+1
end /* %1≡fast way doing TRUNC of a number.*/
r=nr
end /*forever*/
exit /*stick a fork in it, we're all done. */
halt: say; say 'PI_SPIT2 halted via use of Ctrl-Break.'; exit
-- 12 Sep 2025
include Setting
signal on halt
arg digs
if digs = '' then
digs=1000
say 'PI - Gibbons Spigot'
say version
say
numeric digits digs+4
q=1; r=0; t=1; k=1; n=3; l=3; z=0; dot=1
do until z = digs
qq=q+q; tn=t*n
if qq+qq+r-t < tn then do
z=z+1; call CharOut ,n
if dot then do
dot=0; call CharOut ,.
end
nr=(r-tn)*10; n=((((qq+q+r)*10)/t)-n*10)%1
q=q*10
end
else do
nr=(qq+r)*l; tl=t*l; n=(q*(k*7+2)+r*l)/tl%1
q=q*k; t=tl; l=l+2; k=k+1
end
r=nr
end
say
say 'Specified' digs 'digits exhausted.'
call Timer
exit
Halt:
say
say 'Halted because of Ctrl-Break.'
call Timer
exit
include Math