Fast computation of Pi


function pi : number; var a, b, t, x, tempa : number; begin a := 1; b := sqrt( 0.5 ); t := 0.25; x := 1; while a-b>epsilon do begin tempa := a; a := (a+b) / 2; b := sqrt( tempa*b ); t := t - x*sqr(a-tempa); x := 2*x end; pi := sqr(a+b) / (4*t) end;

Pascal source (622.fastpi.p)



© Addison-Wesley Publishing Co. Inc.