In the python documentation for python 3.5 https://docs.python.org/3/library/stdtypes.html
It is said that a left shift bitwise operator int << n is equivalent to the expression int * pow(2,n) but without overflow checking.
But since python automatically promotes integers to longs of arbitrary precision, does this mean that there is literally no difference (since there cant technically ever be an overflow)?
You will not have to worry about overflows in Python unless you are using operations that involve data types that can be overflowed. This does not include Python's built in number types (int, float, long, complex).
For positive values of n, the documentation holds. The reason they specify that overflow checking is done is because external libraries, especially those implemented in C, are subject to overflow if such checking is not being done.
As mentioned in the documentation for pow, this is also equivalent to int * (2**n).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With