why the inconsistency?

Alex Martelli aleax at aleax.it
Sat Sep 27 12:34:56 EDT 2003


Richard Brodie wrote:

> 
> "Alex Martelli" <aleax at aleax.it> wrote in message
> news:CxWcb.172171$R32.5498673 at news2.tin.it...
> 
>> 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).
> 
> And if you're really in a hurry 64 * log10(2) is good too ;)

Yep, but it doesn't generalize to an 'x' computed elsewhere,
when all you know is that it's some big integer and need to
know how many digits its decimal representation will take.


Alex





More information about the Python-list mailing list