PEP 237 and long ints

Michael Gilfix mgilfix at eecs.tufts.edu
Wed Apr 17 00:37:14 EDT 2002


  Hi guys. I'm kinda new to the dev list so forgive me if this is
an old thread. Just getting acquainted with the community.  This
particular PEP though touched upon something that I had been dealing
with - getting my longs back into ints. Specifically, I did bitwise
operations on longs (because I had some addition that overflowed and
then took the modulus) and then wanted to cast the result back into
int. It got tricky if my long was particularly large say 4294967295L,
which is really just 0xFFFFFFFF binary and a valid int but difficult
to convert. Instead I had to do a hack where I subtracted a constant
to make the binary equivalent but to bring the value back into integer
range. The PEP seems to suggest making -1 equivalent to the hex long
value. Would this be sufficient to perform the actual type conversion?

  I kinda like having the concept of integer overflow though and am
not sure I'd want my ints to change to longs automagically. It's sort
of a quick sanity check to make sure some calculation isn't running
away (I've caught bugs like that). The PEP suggests having some sort
of warning that would be off by default and then could be turned on
explicitly. But I'm unable to see the difference between handling an
exception in that case explicitly and disabling the warning?  More so,
I'm a little fearful of such features simpley because I would hate to
see a scenario that parallels perl's 'use strict' where any decent,
well-mainting script always turns on such features.

            Regards,

                     -- Mike

-- 
Michael Gilfix
mgilfix at eecs.tufts.edu

For my gpg public key:
http://www.eecs.tufts.edu/~mgilfix/contact.html
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 236 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/python-list/attachments/20020417/9a2ee721/attachment.sig>


More information about the Python-list mailing list