forked from Xor-el/IntXLib4Pascal
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuIntX.pas
More file actions
3201 lines (2571 loc) · 96.9 KB
/
uIntX.pas
File metadata and controls
3201 lines (2571 loc) · 96.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
unit uIntX;
{$I ..\Include\IntXLib.inc}
interface
uses
{$IFDEF DELPHI}
Generics.Collections,
{$ENDIF DELPHI}
Math,
SysUtils,
{$IFDEF DEBUG}
SyncObjs,
{$ENDIF DEBUG}
uIntXGlobalSettings,
uIntXSettings,
uEnums,
uStrings,
uIntXLibTypes;
type
/// <summary>
/// numeric record which represents arbitrary-precision integers.
/// </summary>
TIntX = record
/// <summary>
/// big integer digits.
/// </summary>
_digits: TIntXLibUInt32Array;
/// <summary>
/// big integer digits length.
/// </summary>
_length: UInt32;
/// <summary>
/// big integer sign ("-" if true).
/// </summary>
_negative: Boolean;
/// <summary>
/// used to check if <see cref="TIntX" /> was Zero Initialized.
/// </summary>
_zeroinithelper: Boolean;
class var
/// <summary>
/// instance of <see cref="TIntXGlobalSettings" />.
/// </summary>
_globalSettings: TIntXGlobalSettings;
/// <summary>
/// instance of <see cref="TIntXSettings" />.
/// </summary>
_settings: TIntXSettings;
/// <summary>
/// <see cref="TFormatSettings" /> used in <see cref="TIntX" />.
/// </summary>
_FS: TFormatSettings;
{$IFDEF DEBUG}
/// <summary>
/// Critical Section for maximal error during FHT rounding (debug-mode only).
/// </summary>
_maxFhtRoundErrorCriticalSection: TCriticalSection;
/// <summary>
/// Maximal error during FHT rounding (debug-mode only).
/// </summary>
MaxFhtRoundError: Double;
{$ENDIF DEBUG}
strict private
/// <summary>
/// <see cref="TIntX" /> instance settings getter and setter.
/// </summary>
function GetSettings: TIntXSettings;
procedure SetSettings(value: TIntXSettings);
/// <summary>
/// isodd getter.
/// </summary>
function GetIsOdd: Boolean;
/// <summary>
/// isNegative getter.
/// </summary>
function GetIsNegative: Boolean;
/// <summary>
/// isZero getter.
/// </summary>
function GetIsZero: Boolean;
/// <summary>
/// isOne getter.
/// </summary>
function GetIsOne: Boolean;
/// <summary>
/// IsPowerOfTwo getter.
/// </summary>
function GetIsPowerOfTwo: Boolean;
/// <summary>
/// Getter function for <see cref="TIntX.Clone" />
/// </summary>
function GetClone: TIntX;
/// <summary>
/// Getter function for <see cref="TIntX.Zero" />
/// </summary>
class function GetZero: TIntX; static;
/// <summary>
/// Getter function for <see cref="TIntX.One" />
/// </summary>
class function GetOne: TIntX; static;
/// <summary>
/// Getter function for <see cref="TIntX.MinusOne" />
/// </summary>
class function GetMinusOne: TIntX; static;
/// <summary>
/// Getter function for <see cref="TIntX.Ten" />
/// </summary>
class function GetTen: TIntX; static;
/// <summary>
/// Getter function for <see cref="TIntX.GlobalSettings" />
/// </summary>
class function GetGlobalSettings: TIntXGlobalSettings; static;
/// <summary>
/// Initializes record instance from zero.
/// For internal use.
/// </summary>
procedure InitFromZero();
/// <summary>
/// Initializes record instance from <see cref="UInt64" /> value.
/// Doesn't initialize sign.
/// For internal use.
/// </summary>
/// <param name="value">Unsigned Int64 value.</param>
procedure InitFromUlong(value: UInt64);
/// <summary>
/// Initializes record instance from another <see cref="TIntX" /> value.
/// For internal use.
/// </summary>
/// <param name="value">TIntX value.</param>
procedure InitFromIntX(value: TIntX);
/// <summary>
/// Initializes record instance from digits array.
/// For internal use.
/// </summary>
/// <param name="digits">Big integer digits.</param>
/// <param name="negative">Big integer sign.</param>
/// <param name="mlength">Big integer length.</param>
procedure InitFromDigits(digits: TIntXLibUInt32Array; negative: Boolean;
mlength: UInt32);
public
/// <summary>
/// <see cref="TIntX" /> instance settings property.
/// </summary>
property Settings: TIntXSettings read GetSettings write SetSettings;
/// <summary>
/// Gets flag indicating if big integer is odd.
/// </summary>
property IsOdd: Boolean read GetIsOdd;
/// <summary>
/// Gets flag indicating if big integer is negative.
/// </summary>
property IsNegative: Boolean read GetIsNegative;
/// <summary>
/// Gets flag indicating if big integer is zero.
/// </summary>
property IsZero: Boolean read GetIsZero;
/// <summary>
/// Gets flag indicating if big integer is one.
/// </summary>
property IsOne: Boolean read GetIsOne;
/// <summary>
/// Gets flag indicating if big integer is a power of two.
/// </summary>
property IsPowerOfTwo: Boolean read GetIsPowerOfTwo;
/// <summary>
/// Returns a copy of the current <see cref="TIntX" />, with a unique copy of the data.
/// </summary>
property Clone: TIntX read GetClone;
/// <summary>
/// A Zero.
/// </summary>
class property Zero: TIntX read GetZero;
/// <summary>
/// A Positive One.
/// </summary>
class property One: TIntX read GetOne;
/// <summary>
/// A Negative One.
/// </summary>
class property MinusOne: TIntX read GetMinusOne;
/// <summary>
/// A Ten.
/// </summary>
class property Ten: TIntX read GetTen;
/// <summary>
/// <see cref="TIntX" /> global settings.
/// </summary>
class property GlobalSettings: TIntXGlobalSettings read GetGlobalSettings;
// -- Class Constructor and Destructor --
class constructor Create();
class destructor Destroy();
// -- Constructors --
/// <summary>
/// Creates new big integer from integer value.
/// </summary>
/// <param name="value">Integer value to create big integer from.</param>
constructor Create(value: Integer); overload;
/// <summary>
/// Creates new big integer from unsigned integer value.
/// </summary>
/// <param name="value">Unsigned integer value to create big integer from.</param>
constructor Create(value: UInt32); overload;
/// <summary>
/// Creates new big integer from Int64 value.
/// </summary>
/// <param name="value">Int64 value to create big integer from.</param>
constructor Create(value: Int64); overload;
/// <summary>
/// Creates new big integer from unsigned Int64 value.
/// </summary>
/// <param name="value">Unsigned Int64 value to create big integer from.</param>
constructor Create(value: UInt64); overload;
/// <summary>
/// Creates new big integer from a Double value.
/// replicates Microsoft Double to BigInteger Implementation.
/// </summary>
/// <param name="value">
/// Double value to create big integer from.
/// </param>
constructor Create(value: Double); overload;
/// <summary>
/// Creates new big integer from array of it's "digits".
/// Digit with lower index has less weight.
/// </summary>
/// <param name="digits">Array of <see cref="TIntX" /> digits.</param>
/// <param name="negative">True if this number is negative.</param>
/// <exception cref="EArgumentNilException"><paramref name="digits" /> is a null reference.</exception>
constructor Create(digits: TIntXLibUInt32Array; negative: Boolean);
overload;
/// <summary>
/// Creates new <see cref="TIntX" /> from string.
/// </summary>
/// <param name="value">Number as string.</param>
constructor Create(const value: String); overload;
/// <summary>
/// Creates new <see cref="TIntX" /> from string.
/// </summary>
/// <param name="value">Number as string.</param>
/// <param name="numberBase">Number base.</param>
constructor Create(const value: String; numberBase: UInt32); overload;
/// <summary>
/// Copy constructor.
/// </summary>
/// <param name="value">Value to copy from.</param>
/// <exception cref="EArgumentNilException"><paramref name="value" /> is a null reference.</exception>
constructor Create(value: TIntX); overload;
/// <summary>
/// Creates new empty big integer with desired sign and length.
///
/// For internal use.
/// </summary>
/// <param name="mlength">Desired digits length.</param>
/// <param name="negative">Desired integer sign.</param>
constructor Create(mlength: UInt32; negative: Boolean); overload;
/// <summary>
/// Creates new big integer from array of it's "digits" but with given length.
/// Digit with lower index has less weight.
///
/// For internal use.
/// </summary>
/// <param name="digits">Array of <see cref="TIntX" /> digits.</param>
/// <param name="negative">True if this number is negative.</param>
/// <param name="mlength">Length to use for internal digits array.</param>
/// <exception cref="EArgumentNilException"><paramref name="digits" /> is a null reference.</exception>
constructor Create(digits: TIntXLibUInt32Array; negative: Boolean;
mlength: UInt32); overload;
// -- Operators as functions and some other special mathematical functions --
/// <summary>
/// Multiplies one <see cref="TIntX" /> object by another.
/// </summary>
/// <param name="int1">First big integer.</param>
/// <param name="int2">Second big integer.</param>
/// <param name="mode">Multiply mode set explicitly.</param>
/// <returns>Multiply result.</returns>
class function Multiply(int1: TIntX; int2: TIntX; mode: TMultiplyMode)
: TIntX; static;
/// <summary>
/// Divides one <see cref="TIntX" /> object by another.
/// </summary>
/// <param name="int1">First big integer.</param>
/// <param name="int2">Second big integer.</param>
/// <param name="mode">Divide mode.</param>
/// <returns>Division result.</returns>
class function Divide(int1: TIntX; int2: TIntX; mode: TDivideMode)
: TIntX; static;
/// <summary>
/// Divides one <see cref="TIntX" /> object by another and returns division modulo.
/// </summary>
/// <param name="int1">First big integer.</param>
/// <param name="int2">Second big integer.</param>
/// <param name="mode">Divide mode.</param>
/// <returns>Modulo result.</returns>
class function Modulo(int1: TIntX; int2: TIntX; mode: TDivideMode)
: TIntX; static;
/// <summary>
/// Divides one <see cref="TIntX" /> object by another.
/// Returns both divident and remainder
/// </summary>
/// <param name="int1">First big integer.</param>
/// <param name="int2">Second big integer.</param>
/// <param name="modRes">Remainder big integer.</param>
/// <returns>Division result.</returns>
class function DivideModulo(int1: TIntX; int2: TIntX; out modRes: TIntX)
: TIntX; overload; static;
/// <summary>
/// Divides one <see cref="TIntX" /> object by another.
/// Returns both divident and remainder
/// </summary>
/// <param name="int1">First big integer.</param>
/// <param name="int2">Second big integer.</param>
/// <param name="modRes">Remainder big integer.</param>
/// <param name="mode">Divide mode.</param>
/// <returns>Division result.</returns>
class function DivideModulo(int1: TIntX; int2: TIntX; out modRes: TIntX;
mode: TDivideMode): TIntX; overload; static;
/// <summary>
/// Returns a Non-Negative Random <see cref="TIntX" /> object using Pcg Random.
/// </summary>
/// <returns>Random TIntX value.</returns>
class function Random(): TIntX; static;
/// <summary>
/// Returns a Non-Negative Random <see cref="TIntX" /> object using Pcg Random within the specified Range. (Max not Included)
/// </summary>
/// <param name="Min">Minimum value.</param>
/// <param name="Max">Maximum value (Max not Included)</param>
/// <returns>Random TIntX value.</returns>
class function RandomRange(Min: UInt32; Max: UInt32): TIntX; static;
/// <summary>
/// Calculates absolute value of <see cref="TIntX" /> object.
/// </summary>
/// <param name="value">value to get absolute value of.</param>
/// <returns>Absolute value.</returns>
/// <exception cref="EArgumentNilException"><paramref name="value" /> is a null reference.</exception>
class function AbsoluteValue(value: TIntX): TIntX; static;
/// <summary>
/// The base-10 logarithm of the value.
/// </summary>
/// <param name="value">The value.</param>
/// <returns>The base-10 logarithm of the value.</returns>
/// <remarks> Source : Microsoft .NET Reference on GitHub </remarks>
/// <exception cref="EArgumentNilException"><paramref name="value" /> is a null reference.</exception>
class function Log10(value: TIntX): Double; static;
/// <summary>
/// Calculates the natural logarithm of the value.
/// </summary>
/// <param name="value">
/// The value.
/// </param>
/// <returns>
/// The natural logarithm.
/// </returns>
/// <exception cref="EArgumentNilException">
/// <paramref name="value" /> is a null reference.
/// </exception>
/// <remarks>
/// Source : Microsoft .NET Reference on GitHub
/// </remarks>
class function Ln(value: TIntX): Double; static;
/// <summary>
/// Calculates Logarithm of a number <see cref="TIntX" /> object for a specified base.
/// the largest power the base can be raised to that does not exceed the number.
/// </summary>
/// <param name="base">base.</param>
/// <param name="value">number to get log of.</param>
/// <returns>Log value.</returns>
/// <remarks> Source : Microsoft .NET Reference on GitHub </remarks>
/// <exception cref="EArgumentNilException"><paramref name="value" /> is a null reference.</exception>
class function LogN(base: Double; value: TIntX): Double; overload; static;
/// <summary>
/// Calculates Integer Logarithm of a number <see cref="TIntX" /> object for a specified base.
/// the largest power the base can be raised to that does not exceed the number.
/// </summary>
/// <param name="base">base.</param>
/// <param name="number">number to get Integer log of.</param>
/// <returns>Integer Log.</returns>
/// <seealso href="http://gist.github.com/dharmatech/409723">[IntegerLogN Implementation]</seealso>
/// <exception cref="EArgumentNilException"><paramref name="base" /> is a null reference.</exception>
/// <exception cref="EArgumentNilException"><paramref name="number" /> is a null reference.</exception>
/// <exception cref="EArgumentException"><paramref name="base" /> or <paramref name="number" /> is an invalid argument.</exception>
class function IntegerLogN(base: TIntX; number: TIntX): TIntX;
overload; static;
/// <summary>
/// Calculates Square of <see cref="TIntX" /> object.
/// </summary>
/// <param name="value">
/// value to get square of.
/// </param>
/// <returns>
/// Squared value.
/// </returns>
/// <exception cref="EArgumentNilException">
/// <paramref name="value" /> is a null reference.
/// </exception>
class function Square(value: TIntX): TIntX; static;
/// <summary>
/// Calculates Integer SquareRoot of <see cref="TIntX" /> object
/// </summary>
/// <param name="value">value to get Integer squareroot of.</param>
/// <returns>Integer SquareRoot.</returns>
/// <seealso href="http://www.dahuatu.com/RkWdPBx6W8.html">[IntegerSquareRoot Implementation]</seealso>
/// <exception cref="EArgumentNilException"><paramref name="value" /> is a null reference.</exception>
class function IntegerSquareRoot(value: TIntX): TIntX; static;
/// <summary>
/// Calculates Factorial of <see cref="TIntX" /> object.
/// </summary>
/// <param name="value">value to get factorial of.</param>
/// <returns>Factorial.</returns>
/// <exception cref="EArgumentNilException"><paramref name="value" /> is a null reference.</exception>
class function Factorial(value: TIntX): TIntX; static;
/// <summary>
/// (Optimized GCD).
/// Returns a specified big integer holding the GCD (Greatest common Divisor) of
/// two big integers using Binary GCD (Stein's algorithm).
/// </summary>
/// <param name="int1">First big integer.</param>
/// <param name="int2">Second big integer.</param>
/// <returns>GCD number.</returns>
/// <seealso href="http://lemire.me/blog/archives/2013/12/26/fastest-way-to-compute-the-greatest-common-divisor/">[GCD Implementation]</seealso>
/// <seealso href="https://hbfs.wordpress.com/2013/12/10/the-speed-of-gcd/">[GCD Implementation Optimizations]</seealso>
/// <exception cref="EArgumentNilException"><paramref name="int1" /> is a null reference.</exception>
/// <exception cref="EArgumentNilException"><paramref name="int2" /> is a null reference.</exception>
class function GCD(int1: TIntX; int2: TIntX): TIntX; static;
/// <summary>
/// (LCM).
/// Returns a specified big integer holding the LCM (Least Common Multiple) of
/// two big integers.
/// </summary>
/// <param name="int1">First big integer.</param>
/// <param name="int2">Second big integer.</param>
/// <returns>LCM number.</returns>
/// <exception cref="EArgumentNilException"><paramref name="int1" /> is a null reference.</exception>
/// <exception cref="EArgumentNilException"><paramref name="int2" /> is a null reference.</exception>
class function LCM(int1: TIntX; int2: TIntX): TIntX; static;
/// <summary>
/// Calculate Modular Inverse for two <see cref="TIntX" /> objects using Euclids Extended Algorithm.
/// returns Zero if no Modular Inverse Exists for the Inputs
/// </summary>
/// <param name="int1">First big integer.</param>
/// <param name="int2">Second big integer.</param>
/// <returns>Modular Inverse.</returns>
/// <seealso href="https://en.wikipedia.org/wiki/Modular_multiplicative_inverse">[Modular Inverse Explanation]</seealso>
/// <seealso href="http://www.di-mgt.com.au/euclidean.html">[Modular Inverse Implementation]</seealso>
/// <exception cref="EArgumentNilException"><paramref name="int1" /> is a null reference.</exception>
/// <exception cref="EArgumentNilException"><paramref name="int2" /> is a null reference.</exception>
/// <exception cref="EArgumentException"><paramref name="int1" /> or <paramref name="int2" /> is an invalid argument.</exception>
class function InvMod(int1: TIntX; int2: TIntX): TIntX; static;
/// <summary>
/// Calculates Calculates Modular Exponentiation of <see cref="TIntX" /> object.
/// </summary>
/// <param name="value">value to compute ModPow of.</param>
/// <param name="exponent">exponent to use.</param>
/// <param name="modulus">modulus to use.</param>
/// <returns>Computed value.</returns>
/// <seealso href="https://en.wikipedia.org/wiki/Modular_exponentiation">[Modular Exponentiation Explanation]</seealso>
/// <exception cref="EArgumentNilException"><paramref name="value" /> is a null reference.</exception>
/// <exception cref="EArgumentNilException"><paramref name="exponent" /> is a null reference.</exception>
/// <exception cref="EArgumentNilException"><paramref name="modulus" /> is a null reference.</exception>
/// <exception cref="EArgumentException"><paramref name="modulus" /> is an invalid argument.</exception>
/// <exception cref="EArgumentException"><paramref name="exponent" /> is an invalid argument.</exception>
class function ModPow(value: TIntX; exponent: TIntX; modulus: TIntX)
: TIntX; static;
/// <summary>
/// Calculates Bézoutsidentity for two <see cref="TIntX" /> objects using Euclids Extended Algorithm
/// </summary>
/// <param name="int1">first value.</param>
/// <param name="int2">second value.</param>
/// <param name="bezOne">first bezout value.</param>
/// <param name="bezTwo">second bezout value.</param>
/// <returns>GCD (Greatest Common Divisor) value.</returns>
/// <seealso href="https://en.wikipedia.org/wiki/Bézout's_identity">[Bézout's identity Explanation]</seealso>
/// <seealso href="https://en.wikipedia.org/wiki/Extended_Euclidean_algorithm#Pseudocode">[Bézout's identity Pseudocode using Extended Euclidean algorithm]</seealso>
/// <exception cref="EArgumentNilException"><paramref name="int1" /> is a null reference.</exception>
/// <exception cref="EArgumentNilException"><paramref name="int2" /> is a null reference.</exception>
class function Bezoutsidentity(int1: TIntX; int2: TIntX; out bezOne: TIntX;
out bezTwo: TIntX): TIntX; static;
/// <summary>
/// Checks if a <see cref="TIntX" /> object is Probably Prime using MillerRabin primality test.
/// </summary>
/// <param name="value">big integer to check primality.</param>
/// <param name="Accuracy">Accuracy parameter `k´ of the Miller-Rabin algorithm. Default is 5. The execution time is proportional to the value of the accuracy parameter.</param>
/// <returns>Boolean value.</returns>
/// <seealso href="https://en.wikipedia.org/wiki/MillerRabin_primality_test">[MillerRabin primality test Explanation]</seealso>
/// <seealso href="https://github.com/cslarsen/miller-rabin">[MillerRabin primality test Implementation in C]</seealso>
/// <exception cref="EArgumentNilException"><paramref name="value" /> is a null reference.</exception>
class function IsProbablyPrime(value: TIntX; Accuracy: Integer = 5)
: Boolean; static;
/// <summary>
/// The Max Between Two <see cref="TIntX" /> values.
/// </summary>
/// <param name="left">
/// left value.
/// </param>
/// <param name="right">
/// right value.
/// </param>
/// <returns>
/// The Maximum <see cref="TIntX" /> value.
/// </returns>
/// <exception cref="EArgumentNilException">
/// <paramref name="left" /> is a null reference.
/// </exception>
/// <exception cref="EArgumentNilException">
/// <paramref name="right" /> is a null reference.
/// </exception>
class function Max(left: TIntX; right: TIntX): TIntX; static;
/// <summary>
/// The Min Between Two <see cref="TIntX" /> values.
/// </summary>
/// <param name="left">left value.</param>
/// <param name="right">right value.</param>
/// <returns>The Minimum <see cref="TIntX" /> value.</returns>
/// <exception cref="EArgumentNilException"><paramref name="left" /> is a null reference.</exception>
/// <exception cref="EArgumentNilException"><paramref name="right" /> is a null reference.</exception>
class function Min(left: TIntX; right: TIntX): TIntX; static;
/// <summary>
/// Returns a specified big integer raised to the specified power.
/// </summary>
/// <param name="value">Number to raise.</param>
/// <param name="power">Power.</param>
/// <returns>Number in given power.</returns>
class function Pow(value: TIntX; power: UInt32): TIntX; overload; static;
/// <summary>
/// Returns a specified big integer raised to the specified power.
/// </summary>
/// <param name="value">Number to raise.</param>
/// <param name="power">Power.</param>
/// <param name="multiplyMode">Multiply mode set explicitly.</param>
/// <returns>Number in given power.</returns>
class function Pow(value: TIntX; power: UInt32; multiplyMode: TMultiplyMode)
: TIntX; overload; static;
// String output functions
/// <summary>
/// Returns decimal string representation of this <see cref="TIntX" /> object.
/// </summary>
/// <returns>Decimal number in string.</returns>
function ToString(): String; overload;
/// <summary>
/// Returns string representation of this <see cref="TIntX" /> object in given base.
/// </summary>
/// <param name="numberBase">Base of system in which to do output.</param>
/// <returns>Object string representation.</returns>
function ToString(numberBase: UInt32): String; overload;
/// <summary>
/// Returns string representation of this <see cref="TIntX" /> object in given base.
/// </summary>
/// <param name="numberBase">Base of system in which to do output.</param>
/// <param name="upperCase">Use uppercase for bases from 11 to 16 (which use letters A-F).</param>
/// <returns>Object string representation.</returns>
function ToString(numberBase: UInt32; UpperCase: Boolean): String; overload;
/// <summary>
/// Returns string representation of this <see cref="TIntX" /> object in given base using custom alphabet.
/// </summary>
/// <param name="numberBase">Base of system in which to do output.</param>
/// <param name="alphabet">Alphabet which contains chars used to represent big integer, char position is coresponding digit value.</param>
/// <returns>Object string representation.</returns>
function ToString(numberBase: UInt32; const alphabet: String)
: String; overload;
// -- Conversion functions --
/// <summary>
/// Converts the specified <see cref="TIntX" /> to a Double, if this is possible. returns Infinity (+ or -) if the
/// value of the <see cref="TIntX" /> is too large or too small.
/// uses method found in Microsoft BigInteger source on github.
/// </summary>
function AsDouble: Double;
/// <summary>
/// Converts the specified <see cref="TIntX" /> to an Integer, if this is possible. Raises an EOverFlowException if the
/// value of the <see cref="TIntX" /> is too large.
/// </summary>
function AsInteger: Integer;
/// <summary>
/// Converts the specified <see cref="TIntX" /> to a UInt32, if this is possible. Raises an EOverFlowException if the
/// value of the <see cref="TIntX" /> is too large or is negative.
/// </summary>
function AsUInt32: UInt32;
/// <summary>
/// Converts the specified <see cref="TIntX" /> to an Int64, if this is possible. Raises an EOverFlowException if the
/// value of the <see cref="TIntX" /> is too large.
/// </summary>
function AsInt64: Int64;
/// <summary>
/// Converts the specified <see cref="TIntX" /> to a UInt64, if this is possible. Raises an EOverFlowException if the
/// value of the <see cref="TIntX" /> is too large or is negative.
/// </summary>
function AsUInt64: UInt64;
// String parsing functions
/// <summary>
/// Parses provided string representation of <see cref="TIntX" /> object in decimal base.
/// If number starts from "0" then it's treated as octal; if number starts from "$" or "0x"
/// then it's treated as hexadecimal.
/// </summary>
/// <param name="value">Number as string.</param>
/// <returns>Parsed TIntX object.</returns>
class function Parse(const value: String): TIntX; overload; static;
/// <summary>
/// Parses provided string representation of <see cref="TIntX" /> object.
/// </summary>
/// <param name="value">Number as string.</param>
/// <param name="numberBase">Number base.</param>
/// <returns>Parsed TIntX object.</returns>
class function Parse(const value: String; numberBase: UInt32): TIntX;
overload; static;
/// <summary>
/// Parses provided string representation of <see cref="TIntX" /> object using custom alphabet.
/// </summary>
/// <param name="value">Number as string.</param>
/// <param name="numberBase">Number base.</param>
/// <param name="alphabet">Alphabet which contains chars used to represent big integer, char position is coresponding digit value.</param>
/// <returns>Parsed TIntX object.</returns>
class function Parse(const value: String; numberBase: UInt32;
const alphabet: String): TIntX; overload; static;
/// <summary>
/// Parses provided string representation of <see cref="TIntX" /> object in decimal base.
/// If number starts from "0" then it's treated as octal; if number starts from "$" or "0x"
/// then it's treated as hexadecimal.
/// </summary>
/// <param name="value">Number as string.</param>
/// <param name="mode">Parse mode.</param>
/// <returns>Parsed TIntX object.</returns>
class function Parse(const value: String; mode: TParseMode): TIntX;
overload; static;
/// <summary>
/// Parses provided string representation of <see cref="TIntX" /> object.
/// </summary>
/// <param name="value">Number as string.</param>
/// <param name="numberBase">Number base.</param>
/// <param name="mode">Parse mode.</param>
/// <returns>Parsed TIntX object.</returns>
class function Parse(const value: String; numberBase: UInt32;
mode: TParseMode): TIntX; overload; static;
/// <summary>
/// Parses provided string representation of <see cref="TIntX" /> object using custom alphabet.
/// </summary>
/// <param name="value">Number as string.</param>
/// <param name="numberBase">Number base.</param>
/// <param name="alphabet">Alphabet which contains chars used to represent big integer, char position is coresponding digit value.</param>
/// <param name="mode">Parse mode.</param>
/// <returns>Parsed TIntX object.</returns>
class function Parse(const value: String; numberBase: UInt32;
const alphabet: String; mode: TParseMode): TIntX; overload; static;
/// <summary>
/// Returns equality of this <see cref="TIntX" /> with another big integer.
/// </summary>
/// <param name="n">Big integer to compare with.</param>
/// <returns>True if equals.</returns>
function Equals(n: TIntX): Boolean; overload;
/// <summary>
/// Returns equality of this <see cref="TIntX" /> with another integer.
/// </summary>
/// <param name="n">Integer to compare with.</param>
/// <returns>True if equals.</returns>
function Equals(n: Integer): Boolean; overload;
/// <summary>
/// Returns equality of this <see cref="TIntX" /> with another unsigned integer.
/// </summary>
/// <param name="n">Unsigned integer to compare with.</param>
/// <returns>True if equals.</returns>
function Equals(n: UInt32): Boolean; overload;
/// <summary>
/// Returns equality of this <see cref="TIntX" /> with another Int64.
/// </summary>
/// <param name="n">Int64 to compare with.</param>
/// <returns>True if equals.</returns>
function Equals(n: Int64): Boolean; overload;
/// <summary>
/// Returns equality of this <see cref="TIntX" /> with another unsigned Int64.
/// </summary>
/// <param name="n">unsigned Int64 to compare with.</param>
/// <returns>True if equals.</returns>
function Equals(n: UInt64): Boolean; overload;
/// <summary>
/// Compares current object with another big integer.
/// </summary>
/// <param name="n">Big integer to compare with.</param>
/// <returns>1 if object is bigger than <paramref name="n" />, -1 if object is smaller than <paramref name="n" />, 0 if they are equal.</returns>
function CompareTo(n: TIntX): Integer; overload;
/// <summary>
/// Compares current object with another integer.
/// </summary>
/// <param name="n">Integer to compare with.</param>
/// <returns>1 if object is bigger than <paramref name="n" />, -1 if object is smaller than <paramref name="n" />, 0 if they are equal.</returns>
function CompareTo(n: Integer): Integer; overload;
/// <summary>
/// Compares current object with another unsigned integer.
/// </summary>
/// <param name="n">Unsigned integer to compare with.</param>
/// <returns>1 if object is bigger than <paramref name="n" />, -1 if object is smaller than <paramref name="n" />, 0 if they are equal.</returns>
function CompareTo(n: UInt32): Integer; overload;
/// <summary>
/// Compares current object with another Int64.
/// </summary>
/// <param name="n">Int64 to compare with.</param>
/// <returns>1 if object is bigger than <paramref name="n" />, -1 if object is smaller than <paramref name="n" />, 0 if they are equal.</returns>
function CompareTo(n: Int64): Integer; overload;
/// <summary>
/// Compares current object with another UInt64.
/// </summary>
/// <param name="n">UInt64 to compare with.</param>
/// <returns>1 if object is bigger than <paramref name="n" />, -1 if object is smaller than <paramref name="n" />, 0 if they are equal.</returns>
function CompareTo(n: UInt64): Integer; overload;
/// <summary>
/// Frees extra space not used by digits.
/// </summary>
procedure Normalize();
/// <summary>
/// Retrieves this <see cref="TIntX" /> internal state as digits array and sign.
/// Can be used for serialization and other purposes.
/// Note: please use constructor instead to clone <see cref="TIntX" /> object.
/// </summary>
/// <param name="digits">Digits array.</param>
/// <param name="negative">Is negative integer.</param>
/// <param name="zeroinithelper">Is zero initialized?.</param>
procedure GetInternalState(out digits: TIntXLibUInt32Array;
out negative: Boolean; out zeroinithelper: Boolean);
/// <summary>
/// Frees extra space not used by digits only if auto-normalize is set for the instance.
/// </summary>
procedure TryNormalize();
/// <summary>
/// Compare two records to check if they are same.
/// </summary>
/// <param name="Rec1">Record one to compare.</param>
/// <param name="Rec2">Record two to compare.</param>
/// <returns>Boolean value (True if they contain the Same contents else False).</returns>
class function CompareRecords(Rec1: TIntX; Rec2: TIntX): Boolean;
static; inline;
// -- Comparison operators --
/// <summary>
/// Compares two <see cref="TIntX" /> objects and returns true if their internal state is equal.
/// </summary>
/// <param name="int1">First big integer.</param>
/// <param name="int2">Second big integer.</param>
/// <returns>True if equals.</returns>
class operator Equal(int1: TIntX; int2: TIntX): Boolean;
/// <summary>
/// Compares <see cref="TIntX" /> object with integer and returns true if their internal state is equal.
/// </summary>
/// <param name="int1">big integer.</param>
/// <param name="int2">integer.</param>
/// <returns>True if equals.</returns>
class operator Equal(int1: TIntX; int2: Integer): Boolean;
/// <summary>
/// Compares integer with <see cref="TIntX" /> object and returns true if their internal state is equal.
/// </summary>
/// <param name="int1">integer.</param>
/// <param name="int2">big integer.</param>
/// <returns>True if equals.</returns>
class operator Equal(int1: Integer; int2: TIntX): Boolean;
/// <summary>
/// Compares <see cref="TIntX" /> object with unsigned integer and returns true if their internal state is equal.
/// </summary>
/// <param name="int1">big integer.</param>
/// <param name="int2">unsigned integer.</param>
/// <returns>True if equals.</returns>
class operator Equal(int1: TIntX; int2: UInt32): Boolean;
/// <summary>
/// Compares unsigned integer with <see cref="TIntX" /> object and returns true if their internal state is equal.
/// </summary>
/// <param name="int1">unsigned integer.</param>
/// <param name="int2">big integer.</param>
/// <returns>True if equals.</returns>
class operator Equal(int1: UInt32; int2: TIntX): Boolean;
/// <summary>
/// Compares <see cref="TIntX" /> object with Int64 and returns true if their internal state is equal.
/// </summary>
/// <param name="int1">big integer.</param>
/// <param name="int2">Int64.</param>
/// <returns>True if equals.</returns>
class operator Equal(int1: TIntX; int2: Int64): Boolean;
/// <summary>
/// Compares Int64 with <see cref="TIntX" /> object and returns true if their internal state is equal.
/// </summary>
/// <param name="int1">Int64.</param>
/// <param name="int2">big integer.</param>
/// <returns>True if equals.</returns>
class operator Equal(int1: Int64; int2: TIntX): Boolean;
/// <summary>
/// Compares <see cref="TIntX" /> object with UInt64 and returns true if their internal state is equal.
/// </summary>
/// <param name="int1">big integer.</param>
/// <param name="int2">UInt64.</param>
/// <returns>True if equals.</returns>
class operator Equal(int1: TIntX; int2: UInt64): Boolean;
/// <summary>
/// Compares UInt64 with <see cref="TIntX" /> object and returns true if their internal state is equal.
/// </summary>
/// <param name="int1">UInt64.</param>
/// <param name="int2">big integer.</param>
/// <returns>True if equals.</returns>
class operator Equal(int1: UInt64; int2: TIntX): Boolean;
/// <summary>
/// Compares two <see cref="TIntX" /> objects and returns true if their internal state is not equal.
/// </summary>
/// <param name="int1">First big integer.</param>
/// <param name="int2">Second big integer.</param>
/// <returns>True if not equals.</returns>
class operator NotEqual(int1: TIntX; int2: TIntX): Boolean;
/// <summary>
/// Compares <see cref="TIntX" /> object with integer and returns true if their internal state is not equal.
/// </summary>
/// <param name="int1">big integer.</param>
/// <param name="int2">integer.</param>
/// <returns>True if not equals.</returns>
class operator NotEqual(int1: TIntX; int2: Integer): Boolean;
/// <summary>
/// Compares integer with <see cref="TIntX" /> object and returns true if their internal state is not equal.