why the inconsistency?
Alex Martelli
aleax at aleax.it
Fri Sep 26 08:45:22 EDT 2003
Christos TZOTZIOY Georgiou wrote:
> On 23 Sep 2003 18:04:33 -0700, rumours say that mensanator at aol.com
> (mensanator) might have written:
>
> [snipped]
>>But if I want to know how many digits 2**64 has, I can't
>>just do
>
> If only math.log(2**64)/math.log(10) worked with longs without
> converting them into floats first... :(
I'm not sure how you'd compute log on integer numbers. Anyway,
if you're in a hurry to know the number of digits in 2**64 -- I
see math.log(x,10) taking about 4 usec per loop, len(str(x)) about
6.3, in each case with x=2*64 and measuring with timeit.py
(elapsed time, as I'm measuring on Linux).
gmpy.numdigits(x) repeatably takes a bit less than 2 usec per loop;
if you're interested in speedy computations with "multi-precision"
values (integers, rationals, OR floats), you could do worse than
looking into gmpy (plug, plug;-).
(Note: all times measured on my old Athlon -- I did choose an Ahtlon,
back about 30 months ago, exactly because I had seen benchmarks where
it outperformed Intel CPU's by a mile on multi-precision integral
computations, particularly with the GMP library...).
Alex
More information about the Python-list
mailing list