I didn't know boolean could be used with case... But for the compiler it propably produces 2 if clauses which takes away more cpu cycles.
From the comments, this does seem more optimized approach:
Code:
function CalculatePi(aIterations: Cardinal): Extended;
var
Counter: Cardinal;
Denominator, Sign: integer;
begin
Counter := 0;
Denominator := 3;
Sign := -1;
Result := 1.0;
repeat
Result := Result + (Sign/Denominator);
Inc(Counter);
Inc(Denominator, 2); // if you like Inc, go all the way
Sign := -Sign;
until Counter >= aIterations ;
Result := Result * 4.0;
end;
Bookmarks