[docs] [issue29710] Incorrect representation caveat on bitwise operation docs

Nick Coghlan report at bugs.python.org
Sat Jul 14 09:09:01 EDT 2018

Nick Coghlan <ncoghlan at gmail.com> added the comment:

I think we have a fairly different notion of what clarity means here - I have no mental concept whatsoever of how to do two's complement arithmetic with an infinite number of sign bits (I learned most of what I know about two's complement by working with fixed point 16-bit and 32-bit microprocessors), so the infinite bits explanation provides me with very little useful insight, whereas I can readily cope with the notion of storing a single extra sign extension bit beyond the minimum required to hold the operands' two's complement representations.

That said, I do like the idea of using infinite precision arithmetic as the formal definition of the intended language semantics, which would lead to wording like the following:

Each bitwise operation has the same result as though carried out in two's complement with an infinite number of sign bits. In practice, performing the calculation with one extra sign extension bit (a bit-width of ``1 + max(x.bit_length(), y.bit_length()``) is sufficient to get the expected result.


Python tracker <report at bugs.python.org>

More information about the docs mailing list