<div dir="ltr"><div class="gmail_quote"><div dir="ltr">On Sun, Sep 30, 2018 at 11:04 AM Chris Angelico <<a href="mailto:rosuav@gmail.com">rosuav@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">On Mon, Oct 1, 2018 at 12:58 AM David Mertz <<a href="mailto:mertz@gnosis.cx" target="_blank">mertz@gnosis.cx</a>> wrote:<br>
>> I'm not sure what's going on. I have a Py3 busily calculating<br>
>> 2**(2**65) and it's pegging a CPU core while progressively consuming<br>
>> memory, but it responds to Ctrl-C, which suggests that Python bytecode<br>
>> is still being executed.<br>> I'm not quite sure, but my guess is that at SOME POINT you'll get an overflow exception when the current value gets too big to store as a native int.  Or maybe it'll be a segfault; I don't know.<br>>>> "a" * (2**63 - 1)<br>
Traceback (most recent call last):<br>
  File "<stdin>", line 1, in <module><br>
MemoryError<br>
<br>
Bam, instant. (Interestingly, trying to use 2**63 says "OverflowError:<br>
cannot fit 'int' into an index-sized integer", suggesting that<br>
"index-sized integer" is signed, even though a size can and should be<br>
unsigned.) Were there some kind of hard limit, it would be entirely<br>
possible to exceed that and get an instant error, without actually<br>
calculating all the way up there. But it looks like that doesn't<br>
happen.<br></blockquote><div><br></div><div>Sure, it wouldn't be THAT hard to do bounds checking in the Python implementation  to make '2**(2**65))' an instance error rather than a wait-to-exhaust-swap one.  But it's a corner case, and probably not worth the overhead for all the non-crazy uses of integer arithmetic.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">In any case, the colloquial definition that I usually cite ("Python<br>
can store infinitely big integers" or "integers can be as big as you<br>
have RAM to store") is within epsilon of correct :D<br></blockquote><div><br></div><div>I teach the same thing.  For beginners or intermediate students, I just say "unbounded ints." Occasionally for advanced students I add the footnote.</div><div> </div></div><div><br></div>-- <br><div dir="ltr" class="gmail_signature" data-smartmail="gmail_signature">Keeping medicines from the bloodstreams of the sick; food <br>from the bellies of the hungry; books from the hands of the <br>uneducated; technology from the underdeveloped; and putting <br>advocates of freedom in prisons.  Intellectual property is<br>to the 21st century what the slave trade was to the 16th.<br></div></div>