new bitwise module [was Re: Discussion: new operators ...]

Tim Peters tim_one at email.msn.com
Tue Aug 1 22:21:00 EDT 2000


[Rainer Deyke]
> All bitwise operators except ~ (which could be redefined as
> ~a = a ^ 0xffffffff, with strange but predictable results for
> a > 0xffffffff) still make sense for long integers.  They are
> certainly more useful to me than, say, floating point numbers
> (which I despise).

That's only because they despise everyone <wink>.

I'm just jumping in to defend the integrity of ~ when applied to unbounded
ints.  You can view Python's longs either as integers or as unbounded
bitstrings.  ~long makes good sense under the latter interpretation even
today.  The restriction on the unbounded bitstrings representable in Python
is that either the set of bits set, or the set of bits clear, must be finite
(or, in fancier words, the set of bits must be finite or co-finite).

Within that restriction, the set of representable unbounded bitstrings is
closed under all of ~ & ^ |, and ~ has an obvious interpretation (not to
mention a few actual uses <wink>) as the set complement operator (similarly
for | as set union, etc -- it's all very natural already!).

integers-hath-charms-to-soothe-the-savage-breast-ly y'rs  - tim






More information about the Python-list mailing list