[Python-Dev] Memory size overflows (original) (raw)

Guido van Rossum guido@python.org
Tue, 15 Oct 2002 00:24:56 -0400


I think this discussion is suffering from the desire to over-generalize.

Armin, can you show us how to multiply two nonnegative ints together with an overflow "block" as Tim suggested earlier? I.e. a macro callable as

SAFE_MULTIPLY(destination, src1, src2, on_overflow);

meaning roughly

destination = src1 * src2; if () on_overflow;

I currently use something like this as the overflow test in a few places:

if (src1 && destination / src1 != src2)

but as Tim points out the division can kill us unless src1 is a constant... How would you spell this without doing a division?

--Guido van Rossum (home page: http://www.python.org/~guido/)