Author serhiy.storchaka
Recipients Oren Milman, mark.dickinson, serhiy.storchaka
Date 2017-03-15.08:55:17
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1489568117.43.0.447594281596.issue29816@psf.upfronthosting.co.za>
In-reply-to
Content
Currently the value of right operand of the right shift operator is limited by C Py_ssize_t type.

>>> 1 >> 10**100
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
OverflowError: Python int too large to convert to C ssize_t
>>> (-1) >> 10**100
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
OverflowError: Python int too large to convert to C ssize_t
>>> 1 >> -10**100
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
OverflowError: Python int too large to convert to C ssize_t
>>> (-1) >> -10**100
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
OverflowError: Python int too large to convert to C ssize_t

But this is artificial limitation. Right shift can be extended to support arbitrary integers. `x >> very_large_value` should be 0 for non-negative x and -1 for negative x. `x >> negative_value` should raise ValueError.

>>> 1 >> 10
0
>>> (-1) >> 10
-1
>>> 1 >> -10
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: negative shift count
>>> (-1) >> -10
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: negative shift count
History
Date User Action Args
2017-03-15 08:55:17serhiy.storchakasetrecipients: + serhiy.storchaka, mark.dickinson, Oren Milman
2017-03-15 08:55:17serhiy.storchakasetmessageid: <1489568117.43.0.447594281596.issue29816@psf.upfronthosting.co.za>
2017-03-15 08:55:17serhiy.storchakalinkissue29816 messages
2017-03-15 08:55:17serhiy.storchakacreate