[Python-Dev] Cannot declare the largest integer literal.

Christian Tismer tismer@tismer.com
Sat, 06 May 2000 16:29:07 +0200


Tim Peters wrote:
> 
> [Trent Mick]
> > >>> i = -2147483648
> > OverflowError: integer literal too large
> > >>> i = -2147483648L
> > >>> int(i)   # it *is* a valid integer literal
> > -2147483648
> 
> Python's grammar is such that negative integer literals don't exist; what
> you actually have there is the unary minus operator applied to positive
> integer literals; indeed,

<disassembly snipped>

Well, knowing that there are more negatives than positives
and then coding it this way appears in fact as a design flaw to me.

A simple solution could be to do the opposite:
Always store a negative number and negate it
for positive numbers. A real negative number
would then end up with two UNARY_NEGATIVE
opcodes in sequence. If we had a simple postprocessor
to remove such sequences at the end, we're done.
As another step, it could also adjust all such consts
and remove those opcodes.

This could be a task for Skip's peephole optimizer.
Why did it never go into the core?

ciao - chris

-- 
Christian Tismer             :^)   <mailto:tismer@appliedbiometrics.com>
Applied Biometrics GmbH      :     Have a break! Take a ride on Python's
Kaunstr. 26                  :    *Starship* http://starship.python.net
14163 Berlin                 :     PGP key -> http://wwwkeys.pgp.net
PGP Fingerprint       E182 71C7 1A9D 66E9 9D15  D3CC D4D7 93E2 1FAE F6DF
     where do you want to jump today?   http://www.stackless.com