-2

Is there any library that implements an efficient log10floor function in Python?

Python has accuracy problems for large numbers, but if one simply rounds a logarithm to its floor, then it's possible to have a very simple implementation. I'd rather not code my own, so I'm looking for one.

As an example for Java, Guava implements a very fast log10 function when you want to round to floor.

Pablo
  • 10,425
  • 1
  • 44
  • 67
  • This isn't a problem for Python, this is inherent to any binary floating point representation... – juanpa.arrivillaga Feb 05 '18 at 22:57
  • Thanks for the condescending explanation. I understand that. I'm looking for a solution that doesn't depend on the floating point representation of a logarithm (see Guava link). – Pablo Feb 05 '18 at 23:07

1 Answers1

0

If you only need to work with integers, there's always this slow-but-simple method:

def log10floor(x):
    return len("%d" % x) - 1
Myria
  • 3,372
  • 1
  • 24
  • 42