mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-08-17 00:19:19 +02:00
* patch by Rika to improve IntPower, resolves #40036
This commit is contained in:
parent
44a2d4a1eb
commit
725da25477
@ -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,29 +1070,21 @@ 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
|
begin
|
||||||
if (base = 0.0) and (exponent = 0) then
|
if exponent<0 then
|
||||||
result:=1
|
begin
|
||||||
else
|
base:=1.0/base;
|
||||||
begin
|
exponent:=-exponent;
|
||||||
if exponent<0 then
|
end;
|
||||||
base:=1.0/base;
|
intpower:=1.0;
|
||||||
i:=abs(exponent);
|
while exponent<>0 do
|
||||||
intpower:=1.0;
|
begin
|
||||||
while i>0 do
|
if exponent and 1<>0 then
|
||||||
begin
|
intpower:=intpower*base;
|
||||||
while (i and 1)=0 do
|
exponent:=exponent shr 1;
|
||||||
begin
|
base:=sqr(base);
|
||||||
i:=i shr 1;
|
end;
|
||||||
base:=sqr(base);
|
|
||||||
end;
|
|
||||||
i:=i-1;
|
|
||||||
intpower:=intpower*base;
|
|
||||||
end;
|
|
||||||
end;
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user