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 terry.reedy
Recipients eric.smith, mark.dickinson, terry.reedy, zooko
Date 2009-12-04.22:32:11
SpamBayes Score 2.8207294e-05
Marked as misclassified No
Message-id <1259965934.46.0.882491497225.issue7406@psf.upfronthosting.co.za>
In-reply-to
Content
I consider the binary bitwise operations, for negative ints, to be
either undefined or wrongly implemented. Consider the following (3.1)
>>> 3^2
1
>>> -3^2
-1
>>> 3^-2
-3
>>> -3^-2
3
>>> 2^3
1
>>> -2^3
-3

Something change sign just flips the sign of the result, sometimes it
also changes the magnitude. From the viewpoint of arithmetic, and signed
base-two representations, the latter seems senseless.

The doc says only "The ^ operator yields the bitwise XOR (exclusive OR)
of its arguments, which must be integers." But it does not define what
bitwise XOR means for signed ints, as opposed to unsigned bit strings,
possible interpreted as (unsigned) counts, which is the traditional
domain of bit-operation definition. So there is no way to predict the
result for negative ints. Or rather, the sensible prediction does not
match the observed behavior.

My impression is that Python longs are signed magnitudes. If so, the
bitwise ops should arguably be the signed result of the op on the
magnitudes.
History
Date User Action Args
2009-12-04 22:32:14terry.reedysetrecipients: + terry.reedy, zooko, mark.dickinson, eric.smith
2009-12-04 22:32:14terry.reedysetmessageid: <1259965934.46.0.882491497225.issue7406@psf.upfronthosting.co.za>
2009-12-04 22:32:12terry.reedylinkissue7406 messages
2009-12-04 22:32:11terry.reedycreate