Bug in Python large negative literal assignment?

Tim Peters tim.one at home.com
Mon May 14 02:20:12 EDT 2001


[Keith Dart]
> I seem to have found a bug in how Python assigns the largest negative
> literal:
>
> Python 2.1 (#1, Apr 23 2001, 15:49:36)
> [GCC 2.95.1 19990816/Linux (release)] on linux2
> Type "copyright", "credits" or "license" for more information.
> Sourcing .pythonrc...
> Python> # I cannot assign the following:
> .more.. i = -2147483648
> OverflowError: integer literal too large
> ...

Not a bug but not quite a FAQ either:  If you study Python's grammar, you'll
find that there's no such thing as a negative integer literal in the
language.  What you've got there is a unary negation operator applied to a
(positive) integer literal, and 2147483648 is indeed too large on a 32-bit
box.

For more fun, try

    eval("-2147483648")
and

    int("-2147483648")

One of those works!  Told you it was fun <wink>.





More information about the Python-list mailing list