|
|
|
open source project hosted by : Intro & News Download (stable 02/08) (stable 03/08) Results Movies... Huygen'sLanding Status... Extensions generator Search Engine Project and Community Recommended readings
Link to us Quick Links Submit your link to the DC ring OS People:DubaronVisual Synapse Delphi Packager Lazarus Free Pascal DC projects Calculating Pi Open Directory deltasql Hubble in a bottle! DelphiGL Mutella OLPC Wikipedia Others:LWM MediaVirtual Surgery Terragen Tutorial Crosswords SeeSchloss.org Picas Personal Massager Liberi.ch TGnutella Small world |
A way for computing PiDescription of the plugin greekpi.dllGreekpi is a plugin which computes Pi with the Monte Carlo method. Although not very useful in real life (206 billion of digits of Pi are known), it is a good academic example. The idea is to generate two random numbers between 0 and 1, which are considered as coordinates in the plane. Let’s call these two coordinates x and y. Now the plugin checks if the point (x,y) lies within a circle of radius 1. To do this square x and y, sum them together and check if the result is less than one. If the point (x,y) lies in the circle, increment the counter Sum by one.
function pi(var stk : TStack):Boolean;stdcall;
var
Idx : Integer;
Count,Sum,i : Longint;
begin
Result := False;
Idx := stk.StIdx; {this should speed up and also made the code more readable}
{check if enough parameters
first parameter is number of throws for computing Pi}
if Idx < 1 then Exit;
Count := Trunc(Stk.Stack[Idx]);
if Count > 625000000 then Exit; {parameter is too big and we get an overflow}
Sum := 0;
for i:=1 to Count do
begin
if (Sqr(Random)+Sqr(Random)) < 1 then
Inc(Sum);
end;
{gives result back}
Stk.Stack[Idx]:=4* Sum / Count;
Result := True;
end;
[Introduction]
[Roadmap]
[Screenshots]
[Documentation]
[GPU Terragen]
[P2P Search Engine]
[Titan Movie]
[Seismograph]
[File Distributor]
[Eternity II]
[Project/Contact]
[Download]
[FAQ]
Seeschloss created the initial website. The logo was designed by Mark Grady. Graphics are by David A. Lucas.
GPU, a P2P-computing cluster software, © 2002-2008 by the GPU Development team |