How to store extremely large numbers?

Oleksiy picture Oleksiy · Aug 5, 2013 · Viewed 63.1k times · Source

For example I have a factorial program that needs to save really huge integers that can be 50+ digits long. The absolute maximum primitive data type in C++ is unsigned long long int with a maximum value 18446744073709551615 which is only 20 digits long. Here's the link to the limits of C++: http://www.cplusplus.com/reference/climits/

How do I store numbers that are larger than that in a variable of some sort?

Answer

user220878 picture user220878 · Aug 5, 2013

If you already have a boost dependency (which many people these days do), you can use the boost multi-precision library. In fact, it already has an example of a factorial program that can support output up to 128 bits, though extending it further is pretty trivial.