Integer literal overflow error with -2147483648 but not with 0x80000000 ?

Tim Peters tim_one at email.msn.com
Tue Jan 25 20:55:14 EST 2000


[Mike Fletcher]
> Just wondering if there's a reason for this (doesn't cause a
> problem for me, just seems strange)...
>
> PythonWin 1.5.2 (#0, Apr 13 1999, 10:51:12) [MSC 32 bit (Intel)]
> on win32
> Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam
> Portions Copyright 1994-1999 Mark Hammond (MHammond at skippinet.com.au)
> >>> 0x80000000
> -2147483648
> >>> -2147483648
> Traceback (innermost last):
> OverflowError: integer literal too large
> >>>

Python's grammar is such that negative int literals don't exist:  that's
really the unary minus operator applied to the "one too large" positive int
literal 2147483648.  I once tried twisting Guido's arm into special-casing
the snot out of this snotty case, but he declined the implementation
ugliness.  This is, without doubt, the real reason millions of programmers
refuse to use Python <wink>.  BTW, I believe this is the only exception
other than SyntaxError that can get raised at compile time!

Note that int(-2147483648L) works fine (and for those of you who try that
and get an error, search DejaNews for an explanation of what's wrong with
your obsolete version of gcc <wink>).

every-number-has-its-own-tale-to-tell-ly y'rs  - tim






More information about the Python-list mailing list