Added TBigIntPolynomial.ScaleVariable

This commit is contained in:
Stefan Müller 2024-04-04 20:26:21 +02:00
parent 0bbae0a83e
commit 4c0ff2f23f
1 changed files with 21 additions and 0 deletions

View File

@ -39,6 +39,7 @@ type
property Coefficient[const AIndex: Integer]: TBigInt read GetCoefficient; property Coefficient[const AIndex: Integer]: TBigInt read GetCoefficient;
function CalcValueAt(const AX: Int64): TBigInt; function CalcValueAt(const AX: Int64): TBigInt;
function IsEqualTo(const AOther: TBigIntPolynomial): Boolean; function IsEqualTo(const AOther: TBigIntPolynomial): Boolean;
function ScaleVariable(const AScaleFactor: TBigInt): TBigIntPolynomial;
class function Create(const ACoefficients: array of TBigInt): TBigIntPolynomial; static; class function Create(const ACoefficients: array of TBigInt): TBigIntPolynomial; static;
end; end;
@ -88,6 +89,26 @@ begin
Result := False; Result := False;
end; end;
function TBigIntPolynomial.ScaleVariable(const AScaleFactor: TBigInt): TBigIntPolynomial;
var
len, i: Integer;
factor: TBigInt;
begin
if AScaleFactor <> TBigInt.Zero then
begin
len := Length(FCoefficients);
SetLength(Result.FCoefficients, len);
Result.FCoefficients[0] := FCoefficients[0];
factor := AScaleFactor;
for i := 1 to len - 1 do begin
Result.FCoefficients[i] := FCoefficients[i] * factor;
factor := factor * AScaleFactor;
end;
end
else
SetLength(Result.FCoefficients, 0);
end;
class function TBigIntPolynomial.Create(const ACoefficients: array of TBigInt): TBigIntPolynomial; class function TBigIntPolynomial.Create(const ACoefficients: array of TBigInt): TBigIntPolynomial;
var var
high, i: integer; high, i: integer;