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

Nick Coghlan report at bugs.python.org
Sun Jul 15 04:20:26 EDT 2018


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

OK, that makes sense to me. Given that, there'd be two changes proposed.

1. Replace the opening paragraph of https://docs.python.org/3/library/stdtypes.html#bitwise-operations-on-integer-types (the one I originally quoted when opening this issue) with the text:

=====================
Bitwise operations only make sense for integers. The result of bitwise operations is calculated as though carried out in two's complement with an infinite number of sign bits.
=====================

2. Add a new footnote ``(4)`` to the table for the ``|``, ``^``, and ``&`` entries that reads:

=====================
4. Performing these calculations with at least one extra sign extension bit in the internal representation (a working bit-width of ``1 + max(x.bit_length(), y.bit_length()`` or more) is sufficient to get the same result as if there were an infinite number of sign bits.
=====================

----------

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue29710>
_______________________________________


More information about the docs mailing list