Question

I am writing a little arbitrary precision in c(I know such libraries exist, such as gmp, nut I find it more fun to write it, just to exercise myself), and I would like to know if arrays are the best way to represent very long integers, or if there is a better solution(maybe linked chains)? And secondly how does python work to have big integers?(does it use arrays or another technique ?)

Thanks in advance for any response

Was it helpful?

Solution

Try reading documentation about libgmp, it already implements bigints. From what I see, it seems like integers are implemented as a dynamically allocated which is realloc'd when the number needs to grow. See http://gmplib.org/manual/Integer-Internals.html#Integer-Internals.

OTHER TIPS

Python long integers are implemented as a simple structure with just an object header and an array of integers (which might be either 16- or 32-bit ints, depending on platform).

Code is at http://hg.python.org/cpython/file/f8942b8e6774/Include/longintrepr.h

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top