This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author ncoghlan
Recipients CuriousLearner, docs@python, mark.dickinson, martin.panter, ncoghlan, tim.peters, wolma
Date 2017-11-06.04:03:27
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1509941008.01.0.213398074469.issue29710@psf.upfronthosting.co.za>
In-reply-to
Content
Right, and that's why I think we're better off focusing on the arithmetic explanations wherever they apply. The problem is that for "x | y" and "x & y" there's no avoiding discussing the 2's complement representation.

Martin, would you find the reference to `bit_length()` in the current PR easier to follow if it had a second follow-up sentence like the one below:

===
Bitwise binary operations are semantically equivalent to calculations
using 2's complement in a bit-width of ``1 + max(x.bit_length(), y
.bit_length()``. This choice of bit-width ensures there is sufficient space for the absolute value of both operands, while also providing space for an explicit sign bit (representing the conceptually infinite series of zeros or ones at the left of a 2's complement value).
===

That retains the precision of the currently suggested definition (for the benefit of language implementors), but also spells out the rationale for that definition (the "1 +" is for the sign bit, while the abs() is implicit in the fact that bit_length() assumes 2's complement and hence doesn't allow space for an explicit sign bit).
History
Date User Action Args
2017-11-06 04:03:28ncoghlansetrecipients: + ncoghlan, tim.peters, mark.dickinson, docs@python, martin.panter, wolma, CuriousLearner
2017-11-06 04:03:28ncoghlansetmessageid: <1509941008.01.0.213398074469.issue29710@psf.upfronthosting.co.za>
2017-11-06 04:03:27ncoghlanlinkissue29710 messages
2017-11-06 04:03:27ncoghlancreate