Sign in Join
Wiki copytemporary

BigInteger: what changed

Revision 1 to 2. Removed lines have a minus sign; added lines have a plus sign.

OldNewLine
1-There are several Pascal libraries for BigInteger (and Big Decimals, like 1.23) functionality. The C-based [[gmp|GMP library]] can also be used in Free Pascal, it's not listed here.
1+There are several Pascal libraries for BigInteger (and Big Decimals, like 1.23) functionality. The C-based [[gmp|GMP library]] can also be used in Free Pascal, it's not listed here.
22
3-## fptlsbigint.pas in fcl-hash package in FPC Trunk
3+## fpTlsBigInt in fcl-hash package in Free Pascal
44
5-- Refactored from Ultibo Big Integer unit Copyright (C) 2018 - SoftOz Pty Ltd.
6-- Source Code: <https://gitlab.com/freepascal.org/fpc/source/-/blob/main/packages/fcl-hash/src/fptlsbigint.pas>
5+ * By: Mattias Gaertner
6+ * Source Code: <https://gitlab.com/freepascal.org/fpc/source/-/blob/main/packages/fcl-hash/src/fptlsbigint.pas>
77
8-Inspired by AXTLS - \crypto\bigint.c - Copyright (c) 2007, Cameron Rich\
9-Reference: Handbook of Applied Cryptography (Chapter 14) - <http://cacr.uwaterloo.ca/hac/about/chap14.pdf>
8+Refactored from Ultibo Big Integer unit Copyright (C) 2018 - SoftOz Pty Ltd.
9+Inspired by AXTLS - \crypto\bigint.c - Copyright (c) 2007, Cameron Rich.
10+Reference: Handbook of Applied Cryptography (Chapter 14) - <http://cacr.uwateloo.ca/hac/about/chap14.pdf>
1011
1112## TForge
1213
13-- By: Sergey Kasandrov
14-- Homepage: <https://github.com/Alexey-T/TForge-Pascal>
14+ * By: Sergey Kasandrov
15+ * Homepage: <https://github.com/Alexey-T/TForge-Pascal>
1516
16-Modern cryptographic library for Delphi and Lazarus/FPC implemented as a set of runtime packages. Project development was stopped, the last found snapshot v0.76 was put to GitHub.
17+Modern cryptographic library for Delphi and Lazarus/FPC implemented as a set of runtime packages. Project development was stopped, the last found snapshot v0.76 was put to GitHub.
1718
1819## Big Decimal Math
1920
20-- By: Benito van der Zander
21-- Homepage: <https://benibela.de/sources_en.html#bigdecimalmath>
21+ * By: Benito van der Zander
22+ * Homepage: <https://benibela.de/sources_en.html#bigdecimalmath>
2223
23-This unit provides a BigDecimal-Type which stores arbitrary precision (BCD) decimal numbers and can be used like any native numeric type.
24+This unit provides a BigDecimal-Type which stores arbitrary precision (BCD) decimal numbers and can be used like any native numeric type.
2425
2526## FNX
2627
27-- By: Marcel Martin
28-- Homepage: <https://www.ellipsa.eu/public/fnx/fnx.html>
28+ * By: Marcel Martin
29+ * Homepage: <https://www.ellipsa.eu/public/fnx/fnx.html>
2930
30-Library of multi-precision numbers (currently, only big integers) written for Free Pascal and Linux. The assembler code that can be enabled with a compiler directive, is for x86-64 processors only.
31+Library of multi-precision numbers (currently, only big integers) written for Free Pascal and Linux. The assembler code that can be enabled with a compiler directive, is for x86-64 processors only.
3132
3233## MPArith
3334
34-- By: Wolfgang Ehrhardt
35-- Homepage: <https://github.com/Alexey-T/Wolfgang_Ehrhardt_codes/tree/master/Misc/MPArith>
35+ * By: Wolfgang Ehrhardt
36+ * Homepage: <https://github.com/Alexey-T/Wolfgang_Ehrhardt_codes/tree/master/Misc/MPArith>
3637
37-Project development was stopped in about 2018. The last found snapshot was put to GitHub.
38+Project development was stopped in about 2018. The last found snapshot was put to GitHub.
3839
39-Comment by forum user [MathMan](https://forum.lazarus.freepascal.org/index.php?action=profile;u=55215):
40+Comment by forum user [MathMan](<https://forum.lazarus.freepascal.org/index.php?action=profile;u=55215>):
4041
41-- Functionality
42- - supports 16/32/64 bit, little- & big-endian
43- - pure functional implementation
44- - dynamic sizing
45- - solid error handling (function results or exceptions)
46- - extensive set of functions - arith, bitops, comparisons, type conversion, base conversion
47- - extensive number theory - gcd, modinv, mulmod, pow, powmod, sqrt+remainder, n-root+remainder, and a lot more
42+ * Functionality
43+ * supports 16/32/64 bit, little- & big-endian
44+ * pure functional implementation
45+ * dynamic sizing
46+ * solid error handling (function results or exceptions)
47+ * extensive set of functions - arith, bitops, comparisons, type conversion, base conversion
48+ * extensive number theory - gcd, modinv, mulmod, pow, powmod, sqrt+remainder, n-root+remainder, and a lot more
4849
49-- Algorithms
50- - basecase multiplication only 33% slower than best known pure Pascal
51- - efficient multiplication: Karatsuba, Toom3
52- - efficient squaring: Karatsuba, Toom3
53- - efficient division: Burnikel-Ziegler
54- - div&cong base conversion (both ways)
55- - efficient GCD
56- - efficient modular ops: based on Montgomery & Barrett reductions
57- - efficient roots: quadratically converging
50+ * Algorithms
51+ * basecase multiplication only 33% slower than best known pure Pascal
52+ * efficient multiplication: Karatsuba, Toom3
53+ * efficient squaring: Karatsuba, Toom3
54+ * efficient division: Burnikel-Ziegler
55+ * div&cong base conversion (both ways)
56+ * efficient GCD
57+ * efficient modular ops: based on Montgomery & Barrett reductions
58+ * efficient roots: quadratically converging
5859
59-- Issues
60- - default thresholds & missing tool for auto detection
61- - Burnikel-Ziegler efficiency degrades on large sizes
62- - no class implementation
60+ * Issues
61+ * default thresholds & missing tool for auto detection
62+ * Burnikel-Ziegler efficiency degrades on large sizes
63+ * no class implementation
6364
64-- Nice things
65- - simple to activate under FPC
66- - accompanied by a good manual
67- - extensive test coverage
68- - there is also rationals, reals & complex available with large set of functions
65+ * Nice things
66+ * simple to activate under FPC
67+ * accompanied by a good manual
68+ * extensive test coverage
69+ * there is also rationals, reals & complex available with large set of functions
6970
7071## BigInt
7172
72-- By: Franco Milani
73-- Homepage: <http://spazioinwind.libero.it/frm/software>
73+ * By: Franco Milani
74+ * Homepage: <http://spazioinwind.libero.it/frm/software>
7475
75-Though this is a Pascal source \>90% are coded as x86-32 Win32 assembler routines.
76+Though this is a Pascal source >90% are coded as x86-32 Win32 assembler routines.
7677
7778## HugeInt
7879
79-- By: David J Butler
80-- Homepage: <https://github.com/fundamentalslib/fundamentals5>
80+ * By: David J Butler
81+ * Homepage: <https://github.com/fundamentalslib/fundamentals5>
8182
82-Part of a much larger library but the unit can be used self-contained.
83+Part of a much larger library but the unit can be used self-contained.
8384
8485## LongMathForPascal
8586
86-- By: Zsolt Szakaly
87-- Homepage: <https://github.com/zsoltszakaly/longmathforpascal>
87+ * By: Zsolt Szakaly
88+ * Homepage: <https://github.com/zsoltszakaly/longmathforpascal>
8889
89-A quite recent contribution (2021) - unfortunately it does not support any efficient algorithms and becomes slow very fast.
90+A quite recent contribution (2021) - unfortunately it does not support any efficient algorithms and becomes slow very fast.
9091
9192## GInt
9293
93-- By: Walied Othman
94-- Homepage: <https://github.com/SnakeDoctor/FGInt>
94+ * By: Walied Othman
95+ * Homepage: <https://github.com/SnakeDoctor/FGInt>
9596
96-Again part of a larger library but can be used self-contained.
97+Again part of a larger library but can be used self-contained.
9798
9899## GNURZ
99100
100-- By: Alexander Staidl
101-- Homepage: <https://github.com/afriess/GNURZ>
101+ * By: Alexander Staidl
102+ * Homepage: <https://github.com/afriess/GNURZ>
102103
103-Development was stopped in about 2009 year. Almost all identifiers are in German. Additional unit written in Assembler exists, but it's not required.
104+Development was stopped in about 2009 year. Almost all identifiers are in German. Additional unit written in Assembler exists, but it's not required.
104105
105106## BigIntegers for Delphi
106107
107-- By: Rudy Velthuis
108-- Homepage: <https://github.com/rvelthuis/DelphiBigNumbers>
109-
110-Code can be adapted for Free Pascal. How-to from [Rudy's website](http://www.rvelthuis.de/programs/bigintegers.html):
111-
112- In {$mode delphi}, it is possible to compile the units. FreePascal doesn’t seem to use segmented unit names (yet), so you’ll have to rename some of the used units and qualifiers like System.Math or System.SysUtils to simply Math or SysUtils. At first, you’ll have to {$DEFINE PUREPASCAL}, because making the assembler work satisfactorily could be quite a job. It seems to work alright, if you set {$asmmode intel}, but it is a little finicky. Stuff like LEA EAX,[EDX + EDI*CLimbSize] seems to cause problems, but [EDX + CLimbSize*EDI] works. That is a bit of a problem for me, because I most of the time use the former variety. But I guess that, with enough time on your hands, you can make it work.
108+ * By: Rudy Velthuis
109+ * Homepage: <https://github.com/rvelthuis/DelphiBigNumbers>
113110
111+Code can be adapted for Free Pascal. How-to from [Rudy's website](<http://www.rvelthuis.de/programs/bigintegers.html>):
112+```
113+In {$mode delphi}, it is possible to compile the units. FreePascal doesn’t seem to use segmented unit names (yet), so you’ll have to rename some of the used units and qualifiers like System.Math or System.SysUtils to simply Math or SysUtils. At first, you’ll have to {$DEFINE PUREPASCAL}, because making the assembler work satisfactorily could be quite a job. It seems to work alright, if you set {$asmmode intel}, but it is a little finicky. Stuff like LEA EAX,[EDX + EDI*CLimbSize] seems to cause problems, but [EDX + CLimbSize*EDI] works. That is a bit of a problem for me, because I most of the time use the former variety. But I guess that, with enough time on your hands, you can make it work.
114+
114115 Some of the tricky routines, e.g. ToString, which uses RecursiveToString, which in its turn needs an exact alignment of bytes to get a usable string, don’t work, but in the meantime — until you solved the problem — you can e.g. use (or wrap or rename) .ToStringClassic(10) instead. I guess the tricky routines just need some work and some debugging to make them work under FreePascal. I only tried a quick and dirty test, did not do any extensive tests, but it is obviously possible to make it work. Just don’t give up immediately.
115-
116+
116117 Types like TArray don’t seem to work. And there is no way you can define an array of BigInteger before BigInteger is defined, so you will have to define a type BigIntegerArray = array of BigInteger inside the BigInteger record, as a nested type. You will meet other, similar problems. Another was the fact that there is no DivMod() function for UInt64 types, so you will have to either use the one for Longint or use div and mod separately. It could be that the change I made there is one of the causes for the failure of RecursiveToString. This needs some investigation.
117-
118+
118119 There will be other, simple problems and it is well possible that there are a few not-so-simple problems. But it looks as if BigIntegers can be used in FreePascal.
120+```
119121
120-Comment by forum user [MathMan](https://forum.lazarus.freepascal.org/index.php?action=profile;u=55215):
122+Comment by forum user [MathMan](<https://forum.lazarus.freepascal.org/index.php?action=profile;u=55215>):
121123
122-- Functionality
123- - supports 32/64 bit, little- & big-endian
124- - class implementation with operators & functional replicants
125- - dynamic sizing and immutability
126- - late binding
127- - solid error handling
128- - solid set of operators - arith, bitops, comparisons, expl & impl conversions
129- - some number theory - gcd, modinv, mulmod, pow, powmod, sqrt+remainder, n-root+remainder
130-- Algorithms
131- - basecase multiplication only 33% slower than best known pure Pascal
132- - efficient multiplication: Karatsuba, Toom3
133- - efficient squaring: Karatsuba
134- - efficient division: Burnikel-Ziegler
135- - div&cong base conversion (from binary to arb base only)
136- - euclidean GCD
137-- Issues
138- - tricky to convert to FPC
139- - memory management degrades efficient algs on larger sizes (speed reduced by 5)
140- - default thresholds & missing tool for auto detection
141- - sqr-schoolbook = mul-schoolbook
142- - missing efficient GCD algorithm
143- - missing efficient mod algorithms (Montgomery, Barrett)
144- - the way asm-enhancements are integrated could be improved (subjective)
145- - testing depth & breadth could be improved (subjective)
146-- Nice things
147- - there is also BigDecimals, BigRationals & BigFloats
124+ * Functionality
125+ * supports 32/64 bit, little- & big-endian
126+ * class implementation with operators & functional replicants
127+ * dynamic sizing and immutability
128+ * late binding
129+ * solid error handling
130+ * solid set of operators - arith, bitops, comparisons, expl & impl conversions
131+ * some number theory - gcd, modinv, mulmod, pow, powmod, sqrt+remainder, n-root+remainder
132+ * Algorithms
133+ * basecase multiplication only 33% slower than best known pure Pascal
134+ * efficient multiplication: Karatsuba, Toom3
135+ * efficient squaring: Karatsuba
136+ * efficient division: Burnikel-Ziegler
137+ * div&cong base conversion (from binary to arb base only)
138+ * euclidean GCD
139+ * Issues
140+ * tricky to convert to FPC
141+ * memory management degrades efficient algs on larger sizes (speed reduced by 5)
142+ * default thresholds & missing tool for auto detection
143+ * sqr-schoolbook = mul-schoolbook
144+ * missing efficient GCD algorithm
145+ * missing efficient mod algorithms (Montgomery, Barrett)
146+ * the way asm-enhancements are integrated could be improved (subjective)
147+ * testing depth & breadth could be improved (subjective)
148+ * Nice things
149+ * there is also BigDecimals, BigRationals & BigFloats
148150
149151## Multi-Word-Int
150152
151-- By: Mark Taylor
152-- Homepage: <https://github.com/ad1mt/Multi-Word-Int> or <https://mark-taylor.me.uk/index.php?page=Software>
153+ * By: Mark Taylor
154+ * Homepage: <https://github.com/ad1mt/Multi-Word-Int> or <https://mark-taylor.me.uk/index.php?page=Software>
153155
154-Designed to be:
156+Designed to be:
155157
156-- easy to use, requires minimal changes to existing code
157-- written entirely in Pascal, no assembly or C language, so portable and reliable
158-- works in both 64bit and 32bit environments
159-- compact code base, but has limited maths functions
160-- reasonably fast (although not as fast as MPArith which is around 10x faster)
158+ * easy to use, requires minimal changes to existing code
159+ * written entirely in Pascal, no assembly or C language, so portable and reliable
160+ * works in both 64bit and 32bit environments
161+ * compact code base, but has limited maths functions
162+ * reasonably fast (although not as fast as MPArith which is around 10x faster)
161163
162-NB this is a recent new development, and should be considered beta code.
164+NB this is a recent new development, and should be considered beta code.
163165
164166## See Also
165167
166-- [[Portal:SciTech]]
168+ * [[Portal:SciTech]]
167169
168170---
169-*From the Free Pascal wiki, page "BigInteger", as it stood on 2023-11-18 after a change by WayneSherman, out of the wiki's dump of 2024-05-26. Copyright stays with the author who wrote it, according to the old wiki's [[Licensing]] page. If you have concerns about this material, [message the admin](/wiki-contact).*
170-Category: Comparisons
171-Category: Libraries
172-Category: Mathematics
171+*From the Free Pascal wiki, page "BigInteger", as the Internet Archive kept it on 2024-09-14, last changed on 2024-09-01. Copyright stays with the author who wrote it, according to the old wiki's [[Licensing]] page. If you have concerns about this material, [message the admin](/wiki-contact).*

Back to history