开发者

big integers with fixed length [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.

We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.

Closed 5 years ago.

Improve this question 开发者_开发问答

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


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.


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."


If you find GMP too complicated for your taste, Dave Hanson has some very nice functions in his book C Interfaces and Implementations. There is a low-level interface that does no allocation (you control everything), and then there are two higher-level interfaces that manage progressively more allocation on the heap.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜