[Python-Dev] Memory size overflows

Tim Peters tim.one@comcast.net
Mon, 21 Oct 2002 17:47:02 -0400


[Gerald S. Williams]
> Agreed. Also, signed values needn't be 2's complement numbers,

Python assumes 2's comp in several places already.

> and the behavior of signed overflow isn't guaranteed (it could
> saturate, for instance).

But it doesn't assume anything about what happens on overflow, for either
doubles or for signed integral types.

> The use of doubles makes sense from a portability standpoint.

I thought you were going to time this <wink>?

> Or you could break out the signs and use unsigned longs with
> preprocessor (and configure) checks, being careful about performance
> impact. :-)

Breaking out the signs means tests and branches.  That's something the
int_mult() code in Python tries to avoid.  Unfortunately, there's a ton of
tests and branches before we ever get to the multiplication, trying to guess
whether this is really a "sequence * integer" case.  But once we get to
actually multiplying two ints, the fast path has only one test+branch (did
it overflow?).