On Sun, Sep 30, 2018 at 10:49 AM Chris Angelico <ros...@gmail.com> wrote:
> > int.bit_length() is stored as a system-native integer, e.g. 64-bit, > rather than recursively as a Python int. So the largest Python int is > '2**sys.maxsize` (e.g. '2**(2**63-1)'). I may possibly have an off-by-one > or off-by-power-of-two in there :-). > > Hah. Is that a fundamental limit based on the underlying > representation, or would it mean that bit_length would bomb with an > exception if the number is larger than that? > It's implementation specific. In concept, a version of Python other than CPython 3.7 could store bit-length as either a Python int or a system-native int, to whatever recursive depth was needed to prevent overflows. Or perhaps as a linked list of native ints. Or something else. There's no sane reason to bother doing that, but there's never been a *promise* in Python semantics not to represent numbers with more than 1e19 bits in them. > I'm not sure what's going on. I have a Py3 busily calculating > 2**(2**65) and it's pegging a CPU core while progressively consuming > memory, but it responds to Ctrl-C, which suggests that Python bytecode > is still being executed. > 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. I'm also not sure if you'll see this error before or after the heat death of the universe ;-). I *am* sure that your swap space on your puny few terabyte disk will fill up before you complete the calculation, so that might be a system level crash not a caught exception. -- Keeping medicines from the bloodstreams of the sick; food from the bellies of the hungry; books from the hands of the uneducated; technology from the underdeveloped; and putting advocates of freedom in prisons. Intellectual property is to the 21st century what the slave trade was to the 16th.
_______________________________________________ Python-ideas mailing list Python-ideas@python.org https://mail.python.org/mailman/listinfo/python-ideas Code of Conduct: http://python.org/psf/codeofconduct/