Last active
June 1, 2019 14:22
-
-
Save wuxixigit/1f2782a1e9a4f86441f93fdc1d05f4a5 to your computer and use it in GitHub Desktop.
RemObject Island Oxegene code for calculating Pi.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace Island.CalculatePi; | |
uses | |
rtl; | |
type | |
Program = class | |
private | |
class const cPiDigits = 50000; | |
class const cArrayLen = 10 * cPiDigits div 3; | |
private | |
class var FArray: array[0..cArrayLen] of LongInt; | |
public | |
class method OneLoop(aIndex: Integer): Integer; | |
begin | |
aIndex := aIndex * 10 div 3 + 16; | |
if aIndex > cArrayLen then | |
aIndex := cArrayLen; | |
result := 0; | |
var x: Integer; | |
repeat | |
x := 10 * FArray[aIndex] + result * aIndex; | |
result := x div (2 * aIndex - 1); | |
FArray[aIndex] := x - result * (2 * aIndex - 1); | |
dec(aIndex); | |
until aIndex <= 0 ; | |
end; | |
class method Main(args: array of String): Int32; | |
begin | |
var frequency, startTime, endTime: LARGE_INTEGER; | |
var J, K, Q, nines, preDigits: Integer; | |
QueryPerformanceFrequency(@frequency); | |
QueryPerformanceCounter(@startTime); | |
for J := 1 to cArrayLen do | |
FArray[J] := 2; {Start with 2s} | |
nines := 0; | |
preDigits := 0; {First predigit is a 0} | |
for J := 1 to cPiDigits do | |
begin | |
Q := OneLoop(cPiDigits - J); | |
FArray[1] := Q mod 10; | |
Q := Q div 10; | |
if Q = 9 then | |
nines := nines + 1 | |
else | |
if Q = 10 then | |
begin | |
// write(preDigits + 1); | |
for K := 1 to nines do | |
// write(0); {zeros} | |
preDigits := 0; | |
nines := 0 | |
end | |
else | |
begin | |
// write(preDigits); | |
preDigits := Q; | |
if nines <> 0 then | |
begin | |
for K := 1 to nines do | |
// write(9); | |
nines := 0 | |
end | |
end | |
end; | |
// writeLn(preDigits); | |
QueryPerformanceCounter(@endTime); | |
writeLn(#13#10 + 'RemObject Island Oxegene takes time (sec): ' + (endTime.QuadPart - startTime.QuadPart)/frequency.QuadPart); | |
writeLn('Press any key to exit.'); | |
readLn; | |
end; | |
end; | |
end. | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment