Added some improvements for TBigInt shift left operator
This commit is contained in:
parent
4329041353
commit
2df8266d42
10
UBigInt.pas
10
UBigInt.pas
|
@ -626,8 +626,11 @@ var
|
||||||
begin
|
begin
|
||||||
// Handles shift of zero.
|
// Handles shift of zero.
|
||||||
if A = 0 then
|
if A = 0 then
|
||||||
Result := TBigInt.Zero
|
begin
|
||||||
else begin
|
Result := TBigInt.Zero;
|
||||||
|
Exit;
|
||||||
|
end;
|
||||||
|
|
||||||
// Determines full digit shifts and bit shifts.
|
// Determines full digit shifts and bit shifts.
|
||||||
DivMod(B, CBitsPerDigit, digitShifts, bitShifts);
|
DivMod(B, CBitsPerDigit, digitShifts, bitShifts);
|
||||||
|
|
||||||
|
@ -654,7 +657,7 @@ begin
|
||||||
Result.FDigits[i] := Result.FDigits[i] or (A.FDigits[j] << bitShifts);
|
Result.FDigits[i] := Result.FDigits[i] or (A.FDigits[j] << bitShifts);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
if Length(Result.FDigits) > newLength then
|
if lastDigit > 0 then
|
||||||
Result.FDigits[newLength] := lastDigit;
|
Result.FDigits[newLength] := lastDigit;
|
||||||
end
|
end
|
||||||
else begin
|
else begin
|
||||||
|
@ -669,7 +672,6 @@ begin
|
||||||
|
|
||||||
Result.FIsNegative := A.IsNegative;
|
Result.FIsNegative := A.IsNegative;
|
||||||
end;
|
end;
|
||||||
end;
|
|
||||||
|
|
||||||
operator shr(const A: TBigInt; const B: Integer): TBigInt;
|
operator shr(const A: TBigInt; const B: Integer): TBigInt;
|
||||||
var
|
var
|
||||||
|
|
|
@ -732,7 +732,8 @@ end;
|
||||||
|
|
||||||
{ TBigIntShiftLeftTestCase }
|
{ 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
|
var
|
||||||
a, s: TBigInt;
|
a, s: TBigInt;
|
||||||
begin
|
begin
|
||||||
|
|
Loading…
Reference in New Issue