shift operators?

Donn Cave donn at u.washington.edu
Mon Jan 7 23:30:47 CET 2002


Quoth Andrew Koenig <ark at research.att.com>:
| Jakob> Andrew Koenig wrote:
|
| >> Is it just backward compatibility that keeps 1<<40 from yielding
| >> 1099511627776L as well?
|
| Jakob> No, the fact that you didn't specify that you wanted long 
| Jakob> arithmetic:
|
| I know that I didn't specify long arithmetic.
|
| The point is that other arithmetic operations, such as +, now generate
| long results automatically when the result won't fit in an int.
| So I was asking what is the reason that the shift operators don't
| behave analogously.

I won't pretend to channel anyone for the answer, but it makes sense
to me.

-  The current int shift has properties that seem like they might
   be convenient for some applications - maybe not many, but then
   the operator isn't widely used anyway.  It's for bit fiddling,
   and bits are relative to a hardware word.

-  Change would break any application that expected the current behavior.

-  The alternative is easy enough - use explicit longs, or I suppose
   multiplication by 2 works too?

	Donn Cave, donn at u.washington.edu



More information about the Python-list mailing list