Grab co-authorship; added list of things that will/may change; added
alternative implementation.
This commit is contained in:
parent
77a48daeeb
commit
d975139bb9
49
pep-0237.txt
49
pep-0237.txt
|
@ -1,7 +1,7 @@
|
|||
PEP: 237
|
||||
Title: Unifying Long Integers and Integers
|
||||
Version: $Revision$
|
||||
Author: pep@zadka.site.co.il (Moshe Zadka)
|
||||
Author: pep@zadka.site.co.il (Moshe Zadka), guido@python.org (Guido van Rossum)
|
||||
Status: Draft
|
||||
Type: Standards Track
|
||||
Created: 11-Mar-2001
|
||||
|
@ -18,6 +18,10 @@ Abstract
|
|||
types from the perspective of both the Python interpreter and the
|
||||
C API.
|
||||
|
||||
Note from second author: this PEP requires more thought about
|
||||
implementation details. I've started to make a list of semantic
|
||||
differences but I doubt it's complete.
|
||||
|
||||
|
||||
Rationale
|
||||
|
||||
|
@ -72,9 +76,39 @@ Overflows
|
|||
aid, and has no guaranteed semantics.
|
||||
|
||||
|
||||
Semantic Differences
|
||||
|
||||
The following operations have (usually subtly) different semantics
|
||||
for short and for long integers, and one will have to change
|
||||
somehow. This is intended to be an exhaustive list; if you know
|
||||
of anything else that might change, please write the author.
|
||||
|
||||
- Currently, all arithmetic operators on short ints except <<
|
||||
raise OverflowError if the result cannot be represented as a
|
||||
short int. This will change (of course).
|
||||
|
||||
- Currently x<<n can lose bits for short ints. No more.
|
||||
|
||||
- Currently, hex and oct literals for for short ints may specify
|
||||
negative values; for example 0xffffffff == -1 on a 32-bint
|
||||
machine. No more; this will equal 2**32-1.
|
||||
|
||||
- Currently, repr() of a long int returns a string ending in 'L'
|
||||
while repr() of a short int doesn't. The 'L' will be dropped.
|
||||
|
||||
- Currently, an operation with long operands will never return a
|
||||
short int. This may change.
|
||||
|
||||
- Currently, type(x) may reveal the difference between short and
|
||||
long ints. This may or may not change (see Implementation
|
||||
below).
|
||||
|
||||
|
||||
Implementation
|
||||
|
||||
The PyInt type's slot for a C long will be turned into a
|
||||
There are two alternative implementations to choose from.
|
||||
|
||||
1. The PyInt type's slot for a C long will be turned into a
|
||||
|
||||
union {
|
||||
long i;
|
||||
|
@ -84,10 +118,13 @@ Implementation
|
|||
} bignum;
|
||||
};
|
||||
|
||||
Only the n-1 lower bits of the long have any meaning; the top bit
|
||||
is always set. This distinguishes the union. All PyInt functions
|
||||
will check this bit before deciding which types of operations to
|
||||
use.
|
||||
Only the n-1 lower bits of the long have any meaning; the top bit
|
||||
is always set. This distinguishes the union. All PyInt functions
|
||||
will check this bit before deciding which types of operations to
|
||||
use.
|
||||
|
||||
2. The existing short and long int types remain, but the short int
|
||||
returns a long int instead of raising OverflowError.
|
||||
|
||||
|
||||
Jython Issues
|
||||
|
|
Loading…
Reference in New Issue