* patch by Rika to improve IntPower, resolves #40036

This commit is contained in:
florian 2022-12-13 19:39:42 +01:00
parent 44a2d4a1eb
commit 725da25477

View File

@ -396,7 +396,7 @@ function LnXP1(x : float) : float;
function Power(base,exponent : float) : float; function Power(base,exponent : float) : float;
{ base^exponent } { base^exponent }
function IntPower(base : float;const exponent : Integer) : float; function IntPower(base : float;exponent : longint) : float;
operator ** (bas,expo : float) e: float; inline; operator ** (bas,expo : float) e: float; inline;
operator ** (bas,expo : int64) i: int64; inline; operator ** (bas,expo : int64) i: int64; inline;
@ -1070,28 +1070,20 @@ function power(base,exponent : float) : float;
end; end;
function intpower(base : float;const exponent : Integer) : float; function intpower(base : float;exponent : longint) : float;
var
i : longint;
begin
if (base = 0.0) and (exponent = 0) then
result:=1
else
begin begin
if exponent<0 then if exponent<0 then
begin
base:=1.0/base; base:=1.0/base;
i:=abs(exponent); exponent:=-exponent;
end;
intpower:=1.0; intpower:=1.0;
while i>0 do while exponent<>0 do
begin begin
while (i and 1)=0 do if exponent and 1<>0 then
begin
i:=i shr 1;
base:=sqr(base);
end;
i:=i-1;
intpower:=intpower*base; intpower:=intpower*base;
end; exponent:=exponent shr 1;
base:=sqr(base);
end; end;
end; end;