RE: [Python-Dev] Tail recursion

On Thu, 27 Nov 2003, Andrew Koenig wrote:
::Lurk mode off:: import math def numdigits(n): assert (n >= 0) and ((n % 1) == 0) if n < 10: return 1 return int(math.log10(n)) + 1 (not iterative, but it'll do :) ::Lurk mode on:: -- Devin devin@whitebread.org http://www.whitebread.org/

[Devin]
Nope, integers in Python are unbounded, and this will deliver wrong answers for "big enough" integers. Depending on the vagaries of your platform C's log10 implementation, it may even deliver a wrong answer for small n near an exact power of 10.

[Devin]
Nope, integers in Python are unbounded, and this will deliver wrong answers for "big enough" integers. Depending on the vagaries of your platform C's log10 implementation, it may even deliver a wrong answer for small n near an exact power of 10.
participants (2)
-
Devin
-
Tim Peters