Ein einfaches Pi-Programm – a simple pi program

 

Mit der folgenden Formel – using the formula

 

          1*1          3*3          5*5           

π = 3 + ----- * (3 + ----- * (3 + ----- * (3 + ...)))

         8*1*3        8*2*5        8*3*7    

 

und dem Programm – and the program

 

program simplepi;{by H.J. Caspar};

 uses crt,dos;

 const n=1000;

 var  i,j,k:integer;c,d,q,u,x:word;

      a    :array[1..n+1] of word;

 

procedure divi(y:word);

begin

 c:=0;for j:=1 to n+1 do

 begin

  x:=a[j]+c;q:=x div y;a[j]:=q;

  d:=x-y*q;c:=10*d;

 end;

end;

 

procedure mult(y:word);

begin

 for j:=1 to n+1 do a[j]:=y*a[j];

 for j:=n+1 downto 1 do

 begin

  u:=a[j] div 10;a[j-1]:=a[j-1]+u;

  a[j]:=a[j] mod 10;

 end;

end;

 

Begin

 clrscr;k:=trunc(n*ln(10)/ln(4));

 for i:=k downto 1 do

 begin

  divi(8);divi(i);mult(2*i-1);divi(2*i+1);

  mult(2*i-1);a[1]:=a[1]+3;

 end;

 for i:=1 to n+1 do

 begin

  write(a[i]);

  if i=1 then write('.');

  if (i mod 7=0)then write(' ');

 end;

 write('...');

 repeat until keypressed;

End.

 

erhält man bei 500 MHz Taktfrequenz 1000 Stellen in einer Sekunde.

1000 digits appear in a second, if a 500 MHz processor is used.

 

Die Formel scheint nicht bekannt zu sein, vgl. J.Arndt/C.Haenel: Pi, Springer, 1999, 2. Aufl., mit ausführlichem Formel- und Literaturverzeichnis.

The formula seems to be unknown, cf. J.Arndt/C.Haenel: Pi, Springer,1999, 2nd ed., with rich formula & litterature index.

 

Sie konvergiert doppelt so schnell wie die Formel von Rabinowitz/Wagon, zitiert in 

It converges double fast in comparison with the Rabinowitz/Wagon formula quoted in

http://www.jjj.de/hfloat/spigot.txt.

 

Das Programm ist besonders einfach, weil es nur zwei Prozeduren enthält, die das schriftliche Dividieren und Multiplizieren nachahmen.

The program is very simple because it contains only two procedures simulating the school division and multiplication.

 

http://www.hjcaspar.de                               (25-02-2000)