[Python-Dev] Tail recursion
Aahz
aahz at pythoncraft.com
Thu Nov 27 12:50:39 EST 2003
On Thu, Nov 27, 2003, Andrew Koenig wrote:
>Tim Peters:
>>
>> A different approach makes iteration much more natural: the number of
>> digits in n (>= 0) is the least i >= 1 such that 10**i > n. Then
>> iterative
>> code is an obvious search loop:
>>
>> i = 1
>> while 10**i <= n:
>> i += 1
>> return i
>
> This code relies on 10**i being exact. Is that guaranteed?
For Python ints, yes.
--
Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/
Weinberg's Second Law: If builders built buildings the way programmers wrote
programs, then the first woodpecker that came along would destroy civilization.
More information about the Python-Dev
mailing list