While doing some random experimentation with a factorial program in C, Python and Scheme. I came across this fact:
In C, using \'unsigned long long\' data type, the
Data types such as int
in C are directly mapped (more or less) to the data types supported by the processor. So the limits on C's int
are essentially the limits imposed by the processor hardware.
But one can implement one's own int
data type entirely in software. You can for example use an array of digits as your underlying representation. May be like this:
class MyInt {
private int [] digits;
public MyInt(int noOfDigits) {
digits = new int[noOfDigits];
}
}
Once you do that you may use this class and store integers containing as many digits as you want, as long as you don't run out memory.
Perhaps Python is doing something like this inside its virtual machine. You may want to read this article on Arbitrary Precision Arithmetic to get the details.