[Python-Dev] Memory size overflows

Oren Tirosh oren-py-d@hishome.net
Wed, 16 Oct 2002 04:15:32 -0400


On Tue, Oct 15, 2002 at 01:29:36AM -0400, Tim Peters wrote:
> BTW, if we know we're not interested in anything other than 32-bit products,
> 
>     double _prod = (double)src1 * (double)src2;
>     if (_prod < 4294967296.0) /* 2**32 */
>         result = (size_t)_prod;
>     else
>         overflow;

s/_prod;/src1 * src2;/

Re-calculating the product with integer multiplication is probably faster 
than converting a double to integer on any sane CPU. 

I wonder if the old SPARCs that don't have an integer multiply instruction 
actually have a floating point to integer conversion that is faster than 
integer mul. Wasting "expensive" multiplications this way still feels 
blasphemous :)

	Oren