From cfb74da86b00d78d54acf13e931ab86f8731119f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20M=C3=BCller?= Date: Thu, 23 May 2024 21:07:11 +0200 Subject: [PATCH] Added TBigInt.One --- UBigInt.pas | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/UBigInt.pas b/UBigInt.pas index fd34585..cd2fb7c 100644 --- a/UBigInt.pas +++ b/UBigInt.pas @@ -49,6 +49,7 @@ type function CompareToAbsoluteValues(constref AOther: TBigInt): Integer; class function GetZero: TBigInt; static; + class function GetOne: TBigInt; static; // Adds A and B, ignoring their signs and using ReturnNegative instead. The result is // Sign * (Abs(A) + Abs(B)), @@ -76,6 +77,7 @@ type property IsNegative: Boolean read FIsNegative; property Sign: Integer read GetSign; class property Zero: TBigInt read GetZero; + class property One: TBigInt read GetOne; // Returns the index of the most significant bit, i.e. returns integer k, where 2^k is the largest power of 2 that // is less than or equal to the absolute value of the number itself. Returns -1 if the given number is 0. @@ -115,6 +117,7 @@ const CHalfDigitMax = (1 << CHalfBits) - 1; CZero: TBigInt = (FDigits: (0); FIsNegative: False); + COne: TBigInt = (FDigits: (1); FIsNegative: False); { TBigInt } @@ -165,6 +168,11 @@ begin Result := CZero; end; +class function TBigInt.GetOne: TBigInt; +begin + Result := COne; +end; + class function TBigInt.AddAbsoluteValues(constref AA, AB: TBigInt; const AReturnNegative: Boolean): TBigInt; var i, j, lenA, lenB, len, shorter: Integer;