Changeset 52 for branches/ByteArray/BigInt.pas
- Timestamp:
- Nov 16, 2023, 2:01:59 PM (6 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/ByteArray/BigInt.pas
r51 r52 47 47 class operator GreaterThanOrEqual(A, B: TBigInt): Boolean; 48 48 procedure Shrink; 49 function IsNegative: Boolean; 50 function IsZero: Boolean; 51 function IsPositive: Boolean; 49 52 procedure SetByteArray(AData: TArrayOfByte; ASize: TBigIntSize); 50 53 procedure GetByteArray(var AData: TArrayOfByte; ASize: TBigIntSize); 51 54 function Copy(Size: TBigIntSize): TBigInt; 52 property Size: Byte read GetSize write SetSize;55 property Size: TBigIntSize read GetSize write SetSize; 53 56 property Data[Index: TBigIntSize]: Byte read GetData write SetData; 54 57 end; … … 85 88 procedure TBigInt.SetData(Index: TBigIntSize; AValue: Byte); 86 89 begin 87 if Index > Size- 1 then Size := Index + 1;90 if Index > Integer(Size) - 1 then Size := Index + 1; 88 91 FData[Index] := AValue; 89 92 end; … … 241 244 Carry: Byte; 242 245 begin 243 Result.Size := A.Size;246 Result.Size := Max(A.Size, B.Size); 244 247 Carry := 0; 245 248 I := 0; … … 259 262 begin 260 263 Result := A.Size = B.Size; 264 if not Result then Exit; 261 265 for I := 0 to A.Size - 1 do 262 266 if A.FData[I] <> B.FData[I] then begin … … 271 275 begin 272 276 Result := A.Size = B.Size; 277 if not Result then Exit; 273 278 for I := 0 to A.Size - 1 do 274 279 if A.FData[I] <> B.FData[I] then begin … … 280 285 281 286 class operator TBigInt.LessThan(A, B: TBigInt): Boolean; 282 begin 283 287 var 288 Temp: TBigInt; 289 begin 290 Temp := A - B; 291 Result := Temp.IsNegative; 284 292 end; 285 293 286 294 class operator TBigInt.LessThanOrEqual(A, B: TBigInt): Boolean; 287 begin 288 295 var 296 Temp: TBigInt; 297 begin 298 Temp := A - B; 299 Result := Temp.IsNegative or Temp.IsZero; 289 300 end; 290 301 291 302 class operator TBigInt.GreaterThan(A, B: TBigInt): Boolean; 292 begin 293 303 var 304 Temp: TBigInt; 305 begin 306 Temp := A - B; 307 Result := Temp.IsPositive and not Temp.IsZero; 294 308 end; 295 309 296 310 class operator TBigInt.GreaterThanOrEqual(A, B: TBigInt): Boolean; 297 begin 298 311 var 312 Temp: TBigInt; 313 begin 314 Temp := A - B; 315 Result := Temp.IsPositive; 299 316 end; 300 317 … … 307 324 Dec(I); 308 325 Size := I + 1; 326 end; 327 328 function TBigInt.IsNegative: Boolean; 329 begin 330 Result := (FData[Size - 1] and $80) = $80; 331 end; 332 333 function TBigInt.IsZero: Boolean; 334 var 335 I: TBigIntSize; 336 begin 337 Result := True; 338 for I := 0 to Size - 1 do 339 if FData[I] <> 0 then begin 340 Result := False; 341 Break; 342 end; 343 end; 344 345 function TBigInt.IsPositive: Boolean; 346 begin 347 Result := (FData[Size - 1] and $80) = 0; 309 348 end; 310 349 … … 329 368 4: PDWord(@Result.FData[0])^ := PDWord(@FData[0])^; 330 369 8: PQWord(@Result.FData[0])^ := PQWord(@FData[0])^; 370 else Move(PByte(@FData[0])^, PByte(@Result.FData[0])^, Size); 331 371 end; 332 372 end;
Note:
See TracChangeset
for help on using the changeset viewer.