问题
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++.
回答1:
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/
回答2:
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.
来源:https://stackoverflow.com/questions/12649181/integers-of-unlimited-size