From 4c0ff2f23fdbeaea75a4e94bcf74996e88b1c8e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20M=C3=BCller?= Date: Thu, 4 Apr 2024 20:26:21 +0200 Subject: [PATCH] Added TBigIntPolynomial.ScaleVariable --- UPolynomial.pas | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/UPolynomial.pas b/UPolynomial.pas index 4993c3f..13528ff 100644 --- a/UPolynomial.pas +++ b/UPolynomial.pas @@ -39,6 +39,7 @@ type property Coefficient[const AIndex: Integer]: TBigInt read GetCoefficient; function CalcValueAt(const AX: Int64): TBigInt; function IsEqualTo(const AOther: TBigIntPolynomial): Boolean; + function ScaleVariable(const AScaleFactor: TBigInt): TBigIntPolynomial; class function Create(const ACoefficients: array of TBigInt): TBigIntPolynomial; static; end; @@ -88,6 +89,26 @@ begin Result := False; 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; var high, i: integer;