Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

big integers with fixed length [closed]

Tags:

c++

c

biginteger

I am looking for a library for big integers but with fixed width (128 or 256 would be enough). The reason is I don't want any allocation on the heap. I tried to make them myself but implementing multiplication, division and modulo an efficient way seems to be quite a pain.

Does this already exists somewhere ?

Thanks

like image 673
Ben Avatar asked Nov 29 '09 17:11

Ben


2 Answers

Take a look at the GMP library: www.gmplib.org

Quoting from the function categories:

Low-level positive-integer, hard-to-use, very low overhead functions are found in the mpn category. No memory management is performed; the caller must ensure enough space is available for the results. (...)

That seems to be what you need.

like image 183
Nils Pipenbrinck Avatar answered Sep 18 '22 00:09

Nils Pipenbrinck


This at least looks promising (hit number 8 for int128 library on Google).

http://www.mx-3.cz/tringi/www/langen.php?id=int128

"Unlike other large number classes, you can work with these just like with other P.O.D. types (for example store and load from files using fwrite/fread). Internal representation of these is correct 128-bit little-endian integer."

like image 30
Steve Jessop Avatar answered Sep 19 '22 00:09

Steve Jessop