How can you handle absurdly large numbers?

There are several scenarios that programmers need or want to find very large numbers. They are often so large that they challenge the understanding of the programmer. I am talking about things like the largest known number of numbers (with 12978189 digits) and the recently calculated 10 trillion digits pi .

How can you create a program that processes them? This far exceeds an integer, long, double, BigInteger, BigDecimal or something like that. How to create these types of programs to detect these numbers? How can you store them in memory when the corresponding data types do not exist, and they are likely to consume gigabytes of data each?

+4
source share
1 answer

To refer to your specific examples:

  • The 12 millionth digital whole is not very large for the typical β€œbig whole” class. This must be stored in memory.

  • To save 10 trillion digits of Ο€, you can use a disk file and a memory card. You will need a 64-bit OS and application, but you can simply create a 10-terabyte file on disk (you probably need several disks and a file system, such as ZFS , which can store it on disks) and map it to the processor's address space. Algorithms that compute Ο€ (e.g., BBP ) conveniently compute one sixth digit at a time, which fits well in half a byte of memory.

+4
source

All Articles