When testing the limits of how Python 3 handles very large integers (much too large to actually allocate), I noticed that up to 2**69175290276410818320, a MemoryError is raised:
>>> 1 << 69175290276410818320
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
MemoryError
whereas when you request one more bit above that, you get an OverflowError:
>>> 1 << 69175290276410818321
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
OverflowError: too many digits in integer
This change point is at 7*sys.maxsize + sys.maxsize//2 - 231 (for 64-bit Python 3.8.6), which seems kind of arbitrary.
From the Python 3 docs (emphasis mine):
exception OverflowError
Raised when the result of an arithmetic operation is too large to be represented. This cannot occur for integers (which would rather raise MemoryError than give up). However, for historical reasons, OverflowError is sometimes raised for integers that are outside a required range. Because of the lack of standardization of floating point exception handling in C, most floating point operations are not checked.
My question: what are these historical reasons and how did this particular range come about?