Bug in Python large negative literal assignment?
Roman Suzi
rnd at onego.ru
Mon May 14 01:55:22 EDT 2001
On Sun, 13 May 2001, Keith Dart wrote:
That is because 2147483648 can not be represented by
32 bits ;-)
Python constructs numbers by operations:
-2147483648 - is the result of "-" operation
on 2147483648 number.
> 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
> Python> # however, I can do it the following ways:
> .more.. i = -sys.maxint-1
> Python> i
> -2147483648
> Python> i = 0x80000000
> Python> i
> -2147483648
> Python> i = -2147483647 ; i = i - 1
> Python> i
> -2147483648
> Python> i = -2147483647-1
> Python> i
> -2147483648
> Python> i = -2147483648
> OverflowError: integer literal too large
>
> But, no, can't assign a max negative number as decimal literal.
>
>
>
> \\|//
> (O O)
> -- --------------------oOOo~(_)~oOOo----------------------------------------
> Keith Dart
> <mailto:kdart at kdart.com>
> <http://www.kdart.com/>
> ----------------------------------------------------------------------------
> Ever since my brain transplant I ...
> ============================================================================
>
>
Sincerely yours, Roman A.Suzi
--
- Petrozavodsk - Karelia - Russia - mailto:rnd at onego.ru -
More information about the Python-list
mailing list