diff --git a/UPolynomial.pas b/UPolynomial.pas index 13528ff..9a4374f 100644 --- a/UPolynomial.pas +++ b/UPolynomial.pas @@ -40,6 +40,7 @@ type function CalcValueAt(const AX: Int64): TBigInt; function IsEqualTo(const AOther: TBigIntPolynomial): Boolean; function ScaleVariable(const AScaleFactor: TBigInt): TBigIntPolynomial; + function ToString: string; class function Create(const ACoefficients: array of TBigInt): TBigIntPolynomial; static; end; @@ -109,6 +110,18 @@ begin SetLength(Result.FCoefficients, 0); end; +function TBigIntPolynomial.ToString: string; +var + i: Integer; +begin + Result := FCoefficients[0].ToString; + for i := 1 to Length(FCoefficients) - 1 do + if i > 1 then + Result := Result + ' + ' + FCoefficients[i].ToString + ' * x^' + IntToStr(i) + else + Result := Result + ' + ' + FCoefficients[i].ToString + ' * x'; +end; + class function TBigIntPolynomial.Create(const ACoefficients: array of TBigInt): TBigIntPolynomial; var high, i: integer;