[issue8259] left shift operator doesn't accepts long as second argument

owirj report at bugs.python.org
Mon Mar 29 14:29:22 CEST 2010


New submission from owirj <cemu at mail.ru>:

python -V:
Python 2.6.5

Executing on 32-bit machine.

>From documentation ( http://docs.python.org/reference/expressions.html ), "5.7. Shifting operations":
"These operators accept plain or long integers as arguments. The arguments are converted to a common type. They shift the first argument to the left or right by the number of bits given by the second argument."

In interpreter:
>>> x = 2677691728509L << 2147483648L
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
OverflowError: long int too large to convert to int

hint: 2147483648 = (1 << 31)

First argument is long, second is long too, so expected behavior was normal execution. But as seen from the code above interpreter gives overflow error. Looks like he tries to convert second argument to int type, because this code works gracefully:
>>> x = 2677691728509L << 2147483647L

----------
components: None
messages: 101887
nosy: owirj
severity: normal
status: open
title: left shift operator doesn't accepts long as second argument
versions: Python 2.6

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue8259>
_______________________________________


More information about the Python-bugs-list mailing list