In Python, I can write a program to calculate integers of unlimited size. Just the other day I did the one millionth fibonacci number, and it was so large It was unable to fit in the console. If this is possible to do in Python, which to my understanding was written in C, how could one do the same in C++? It has to be possible, otherwise I don't see how it could be done in Python. I also believe there is something similar in Java/C# called a Biginteger, but I couldn't find anything saying how it could be implemented in C++.
These represent numbers in the range -2147483648 through 2147483647. (The range may be larger on machines with a larger natural word size, but not smaller.)
Numeric Types — int , float , complex. There are three distinct numeric types: integers, floating point numbers, and complex numbers.
Integers in Python 3 are of unlimited size. Python 2 has two integer types - int and long.
In Python, integers are zero, positive or negative whole numbers without a fractional part and having unlimited precision, e.g. 0, 100, -10.
Anything is possible in C/C++. You could write you own class called bigInteger and use an array to represent the number, but the best way is to use an already written library for working with big numbers, because those are very well optimized and a huge part of them is written in asm for extra speed. Here are a few examples:
GMP (it provides also a C++ interface)
http://www.imach.uran.ru/cbignum/
Wikipedia lists a number of libraries you can use. Those that are denoted as C libraries can also be used in C++. C++ does not have a built-in bigint type.
As this reference shows, it's generally a good idea to google, check wikipedia and not the least, check the FAQ, before asking.
However, in this case, inexplicably, it seems that the FAQ does not provide an answer.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With