Forum > Third party
New Big Integer library is finished
ad1mt:
I have been working on a new Big Integer library, which I now consider to be finished.
It is designed to be easy to use, with minimal changes required to existing code.
It is written entirely in Pascal, with no assembly or C code, so should be portable to any platform that Free Pascal supports. It has been beta tested on 32bit Solaris Sun, 32bit Raspberry Pi running Linux, and 64bit Intel Windows. It has also been used in another project of mine over several months.
It is reasonably fast, but there are other big integer libraries that are significantly faster.
Available on GITHub https://github.com/ad1mt/Multi-Word-Int
Or from my web page https://mark-taylor.me.uk/index.php?page=Software
I have made the code public domain; no copyright, no license, no warranty. Do whatever you like with this code.
When I first started work on this library, I expected it to be fairly easy/quick, but it took me almost 2 years to finish it; so I hope some people will find it useful and save them a lot of work.
Although I consider the code to be finished, bug reports and suggestions are still welcome.
srvaldez:
hello ad1mt :)
there's a problem, possibly with conversion from longint to Multi_Int_XV, see the comments in the code
--- Code: ---{$MODESWITCH NESTEDCOMMENTS+}
program speed_test;
uses sysutils
, strutils
, strings
, math
, Multi_Int
;
var
big_int_size,
start_time,
end_time :int32;
delta :double;
MV_i,
MV_j,
MV_k :Multi_Int_XV;
n, mm:longint;
begin
big_int_size:= 1876;
Multi_Int_Initialisation(big_int_size);
mm:=99999999;
start_time:= GetTickCount64;
MV_i:=1;
for n:=2 to 10000 do
begin
MV_i:=MV_i*n;
end;
end_time:= GetTickCount64;
delta:= (end_time - start_time) / 1000;
writeln('time elapsed is ', delta:1:6, ' seconds');
MV_j := '99999999'; // mm or 99999999 crashes the div loop
start_time:= GetTickCount64;
for n:=1 to 10 do
begin
MV_i:=MV_i div MV_j; //mm ; // with mm it crashes
end;
end_time:= GetTickCount64;
writeln(MV_i.ToStr);
delta:= (end_time - start_time) / 1000;
writeln('time elapsed is ', delta:1:6, ' seconds');
end.
--- End code ---
abouchez:
Nice code. And thanks for sharing!
I am only concerned about the fact that I did not find a lot of unit tests, which are imho mandatory for such a general purpose library.
I like the fact that you use what I call "half-word" types, i.e. 16-bit on 32-bit CPU, and 32-bit on 64-bit CPU.
This is what I did for my RSA calculation unit, and even in "pure pascal", the FPC compiler gives good performance.
https://github.com/synopse/mORMot2/blob/master/src/crypt/mormot.crypt.rsa.pas#L57
ad1mt:
--- Quote from: abouchez on September 06, 2024, 06:50:52 pm ---I am only concerned about the fact that I did not find a lot of unit tests, which are imho mandatory for such a general purpose library.
--- End quote ---
I have a test program, but I did not make it available, because I did not think anyone would be interested.
unit_test_v12_X.pas is now available on Github in the Demo folder.
N.B. because of the bug that has been reported nearby, the unit_test program will need to be updated soon.
ad1mt:
--- Quote from: srvaldez on August 31, 2024, 07:59:27 pm ---hello ad1mt :)
there's a problem, possibly with conversion from longint to Multi_Int_XV, see the comments in the code
--- End quote ---
Thank you for the bug report.
O.M.G! :o
I will post a fix ASAP.
Navigation
[0] Message Index
[#] Next page