Does Python need a '>>>' operator?
Martin v. Loewis
martin at v.loewis.de
Mon Apr 15 02:29:10 EDT 2002
David Eppstein <eppstein at ics.uci.edu> writes:
> >>> 0x40000000<<1
> -2147483648
>
> This is inconsistent with int-long unification. In fact, I think it is
> a bug. The answer should, of course, be 2147483648L, just as you would
> get by multiplying by 2 instead of shifting.
Indeed, if you write
>>> 0x40000000L<<1
2147483648L
it works the way you expect it to work. Please see
http://www.python.org/peps/pep-0237.html
Python has currently completed phase A of the PEP, meaning that
operations that previously raised an OverflowError now return a long;
nothing else has changed.
Notice that your example is the historic meaning of shift; in phase
B.1, it will change to the arithmetic meaning (multiplication with
2). Since this is a semantic change, you'll get a warning if you make
use of a short int shift that loses a bit.
Regards,
Martin
More information about the Python-list
mailing list