Skip to content

Math: operator int64**int64

To solve @runewalsh 's issue, #40036 (comment 1208250251) . It calculates 123 ** 9 OK.

Small moment: it calcs 2**-1 as 0, not as 1 before.

replace

operator ** (bas,expo : int64) i: int64; inline;
  begin
    i:=round(intpower(bas,expo));
  end;

with

operator ** (base, exponent : int64) res: int64;
begin
  if exponent<0 then
    begin
      if base<=0 then
        raise EInvalidArgument.Create('Non-positive base with negative exponent in **');
      if base=1 then
        res:=1
      else
        res:=0;
      exit;
    end; 
  res:=1;
  while exponent<>0 do
    begin
      if exponent and 1<>0 then
        res:=res*base;
      exponent:=exponent shr 1;
      base:=base*base;
    end;
end;
Edited by Alexey Torgashin
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information