Added some improvements for TBigInt shift left operator

This commit is contained in:
Stefan Müller 2024-05-23 22:01:25 +02:00
parent 4329041353
commit 2df8266d42
2 changed files with 42 additions and 39 deletions

View File

@ -626,8 +626,11 @@ var
begin
// Handles shift of zero.
if A = 0 then
Result := TBigInt.Zero
else begin
begin
Result := TBigInt.Zero;
Exit;
end;
// Determines full digit shifts and bit shifts.
DivMod(B, CBitsPerDigit, digitShifts, bitShifts);
@ -654,7 +657,7 @@ begin
Result.FDigits[i] := Result.FDigits[i] or (A.FDigits[j] << bitShifts);
end;
if Length(Result.FDigits) > newLength then
if lastDigit > 0 then
Result.FDigits[newLength] := lastDigit;
end
else begin
@ -669,7 +672,6 @@ begin
Result.FIsNegative := A.IsNegative;
end;
end;
operator shr(const A: TBigInt; const B: Integer): TBigInt;
var

View File

@ -732,7 +732,8 @@ end;
{ TBigIntShiftLeftTestCase }
procedure TBigIntShiftLeftTestCase.Test(const AHexValueOperand: string; const AShift: Integer; const AHexValueResult: string);
procedure TBigIntShiftLeftTestCase.Test(const AHexValueOperand: string; const AShift: Integer; const AHexValueResult:
string);
var
a, s: TBigInt;
begin