Does Python need a '>>>' operator?

Tim Peters tim.one at comcast.net
Mon Apr 15 00:19:52 EDT 2002


[David Eppstein]
> ...
> The reason I was getting into trouble anyway was because of the way
> right-shifting can change sign:
>
> >>> 0x40000000<<1
> -2147483648

That looks like a left shift to me.  Right shifting in Python never changes
"the sign".

> This is inconsistent with int-long unification.

Very badly so, yes.  It's the prime reason this *part* of unification was
delayed:  it's going to break code.

> In fact, I think it is a bug.

It's functioning as documented and as designed, so while you can call it "a
bug", it's not "a bug" under any meaning of the phrase a developer will
accept.  I think of it is a design error.  Unfortunately, for some kinds of
bit-fiddling code it's a *useful* design error, so we're tiptoeing on raw
eggs here.

  The answer should, of course, be 2147483648L, just as you would
> get by multiplying by 2 instead of shifting.

That is the goal.






More information about the Python-list mailing list