Rationale for core Python numeric types
tim.peters at gmail.com
Thu Jul 15 21:14:47 CEST 2004
>> You're too worried. The only real semantic difference is that
>> a left shift won't throw away bits by magic, and in a
>> platform-dependent way, anymore.
> How does the 1's compliment operator know how many bits to
> return? IOW, what is ~0 going to be?
Python longs are 2's-complement with a conceptually infinite number of
sign bits (whether 0 or 1). So ~0 will be, like ~0L today, an
infinite string of 1 bits. Even today:
>>> (~0) & 0xff
>>> (~0L) & 0xff
>>> ~0 == ~0L == -1
> For much of what I do with Python, fixed width integers would
> be awfully nice -- then I wouldn't have to and everything with
> 0xff, 0xffff, or 0xffffffff to get the results I want.
Nothing about that is planned to change (there are no plans to add
fixed-width ints). I don't think there's even a PEP on the topic
(although I may be wrong about that -- I want them so little I may not
remember such a PEP if it exists).
More information about the Python-list