performance problem in python 2.2

Paul Rubin phr-n2002b at NOSPAMnightsong.com
Fri Jul 26 20:31:01 EDT 2002


Jeff Davis <jdavis at empires.org> writes:
> Strange that you mention that, because I sort of thought I might get  a 
> more precise answer. After all, mine preserves the entire number 2^64, 
> yours just preserves most. Mine might end up losing it all later in the 
> calculations (because there are more multiplications), is that what you 
> mean?

No, on most computers a C integer can't represent numbers like 2**64.
It only has 32 bits.  If you multiply numbers together that overflow
32 bits, you'll get the wrong answer unless the language mysteriously
converted them to floats for you (the rules for that are slightly
obscure).

Python has exact integers (Python "longs" are not to be confused with
C longs which are usually 32 bits) but at a cost.  If you use longs
in Python, your program runs a lot slower.



More information about the Python-list mailing list