Bug in Python large negative literal assignment?

Keith Dart kdart at kdart.com
Mon May 14 03:08:20 EDT 2001


On Mon, 14 May 2001, Roman Suzi wrote:

> On Sun, 13 May 2001, Keith Dart wrote:
> 
> That is because 2147483648 can not be represented by
> 32 bits ;-)

Thanks, but I know 2147483648 cannot be, but -2147483648 can be. 
I think Python aught to allow it. You're right, it is probably doing a
negation on the positive literal, but I have to do some ugly
work-arounds on my project because of this. But, I managed it by
simply assigning it as a hexadecimal number. 


> 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
> 


                           \\|//
                           (O O)
-- --------------------oOOo~(_)~oOOo----------------------------------------
Keith Dart
<mailto:kdart at kdart.com>
<http://www.kdart.com/>
----------------------------------------------------------------------------
Ever since my brain transplant I ...
============================================================================





More information about the Python-list mailing list