Which, for an integer, is equivalent to dividing it by two and rounding down - b //= 2 in Python. The bit-shift operation may be more efficient, though I'd guess that it doesn't make much difference for Python code.
I didn't mean a regular int, rather what python denotes by L. It's arbitrary-sized integer, big int I think they call it. I just wonder how it works internally.
Yeah, I know what you mean. A regular python int is 32 bits. A long int is 64 bits, using the same encoding, two's complement signed integers. So the shift operations work just the same
As opposed to floating point numbers, which are a bit complicated and depend on the interpreter, but are IEEE single or double precision floating point numbers (sign bit, 8/16 exponent bits, 23/47 numeric bits). You can't use shift operations on a float.
is a valid statement in python, foo being of type long. It supports all (I believe) operations that proper integer does. And is nowhere near 64-bits long.
Ooooohhhh I dun goofed. I didn't know python supported arbitrary precision without importing libraries for it. After a little reading, it seems they are implemented as arrays of ints, so I would guess that the same operations are supported.
3
u/takluyver IPython, Py3, etc Aug 19 '17
Which, for an integer, is equivalent to dividing it by two and rounding down -
b //= 2in Python. The bit-shift operation may be more efficient, though I'd guess that it doesn't make much difference for Python code.