Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit da1a221

Browse files
committed
int_lshift(): Simplified/sped overflow-checking.
1 parent 45daeb0 commit da1a221

1 file changed

Lines changed: 2 additions & 4 deletions

File tree

Objects/intobject.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -675,15 +675,13 @@ int_lshift(PyIntObject *v, PyIntObject *w)
675675
return NULL;
676676
return PyInt_FromLong(0L);
677677
}
678-
c = a < 0 ? ~a : a;
679-
c >>= LONG_BIT - 1 - b;
680-
if (c) {
678+
c = a << b;
679+
if (a != Py_ARITHMETIC_RIGHT_SHIFT(long, c, b)) {
681680
if (PyErr_Warn(PyExc_DeprecationWarning,
682681
"x<<y losing bits or changing sign "
683682
"will return a long in Python 2.4 and up") < 0)
684683
return NULL;
685684
}
686-
c = (long)((unsigned long)a << b);
687685
return PyInt_FromLong(c);
688686
}
689687

0 commit comments

Comments
 (0)