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

Christian Tismer tismer@tismer.com
Mon, 08 May 2000 23:52:54 +0200

```Tim Peters wrote:
>
> [Tim]
> > 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; ...
>
> [Christian Tismer]
> > Well, knowing that there are more negatives than positives
> > and then coding it this way appears in fact as a design flaw to me.
>
> Don't know what you're saying here.

On a 2's-complement machine, there are 2**(n-1) negatives, zero, and
2**(n-1)-1 positives. The most negative number cannot be inverted.
Most machines today use the 2's complement.

> Python's grammar has nothing to do with
> the relative number of positive vs negative entities; indeed, in a
> 2's-complement machine it's not even true that there are more negatives than
> positives.

If I read this 1's-complement machine then I believe it.
But we don't need to split hair on known stuff :-)

> Python generates the unary minus for "negative literals"
> because, again, negative literals *don't exist* in the grammar.

Yes. If I know the facts and don't build negative literals into
the grammar, then I call it an oversight. Not too bad but not nice.

> > A simple solution could be to do the opposite:
> > Always store a negative number and negate it
> > for positive numbers.  ...
>
> So long as negative literals don't exist in the grammar, "-2147483648" makes
> no sense on a 2's-complement machine with 32-bit C longs.  There isn't "a
> problem" here worth fixing, although if there is <wink>, it will get fixed
> by magic as soon as Python ints and longs are unified.

I'd change the grammar.

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