Compute of Pi number
Delphi & Pascal (česká wiki)
Category: KMP (Club of young programmers)
Author: Ľuboš Saloky
Program: Pi.pas, Pi2.pas
File exe: Pi.exe, Pi2.exe
Author: Ľuboš Saloky
Program: Pi.pas, Pi2.pas
File exe: Pi.exe, Pi2.exe
Compute of Pi number.
{ pi.pas } { Vypocet cisla Pi. } { } { Author: Ľuboš Saloky } { Datum: 01.01.1996 http://www.trsek.com } {$G+} program Vypocet_Cisla_pi; { pi=3.14159 26535 89763 23846 26433 83279 50288 41971 } var x:longint; y,t:real; ch:char; a,b:word; begin writeln(501*65536); writeln('1 - Vypocet čísla Pi'); writeln('2 - Test na for longint'); writeln('3 - Test na for word'); readln(ch); case ch of '1':begin y:=1;x:=3; repeat y:=y-1/x; Inc(x,2); t:=1/x; if (x-1) mod 50000=0 then writeln(4*y); y:=y+1/x; Inc(x,2); until t<0.000001; {pre t<0.000001 cas 31 sekĂşnd} writeln(4*y); {4*y= 3.14159465} end; {of case 1} '2':begin for x:=1 to 20000000 do {8 sekund pre x longint} begin end; end; {of case 2} '3':begin for a:=0 to 500 do begin {11 sekund bez asm nop} asm {asm zvysuje Ăşcinnost cache,pretoze tieto} nop {dva cykly sa asi navzĂĄjom z cache vyradujĂş} end; {s asm len 9 sekĂşnd} for b:=0 to 65535 do {mimochodom 501*65516=32833536} begin end;{pri vypnutej externej cache je cas 9 sekĂşnd bez aj s NOP} end; {po vypnutĂ vsetkych kesĂ neuveritelnych 49 sekĂşnd} end; {of case 3} end; {of case total} end. {----------------------------------------------------------------------------} { Zaver: medzi kazde dva prikazy vetvenia davaj NOP } {----------------------------------------------------------------------------}