Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Is there a more efficient way to compute the first digit of a number?

I need to compute the first digit of some large numbers. So far I've been converting them to strings, although it can be somewhat slow. For example:

sage: %timeit str(2^57885161)[0]
1 loops, best of 3: 3.07 s per loop

Is there a faster way to to do this? For my purpose you can assume that all the numbers involved are powers of some small base.