Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
RemObject Island Oxegene code for calculating Pi.
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