title: Imprecise results of logarithm and power functions in Python
body: <p>I am trying to complete the following exercise:
  <a href="https://www.codewars.com/kata/whats-a-perfect-power-anyway/train/python" rel="nofollow">https://www.codewars.com/kata/whats-a-perfect-power-anyway/train/python</a></p>
  
  <p>I tried multiple variations, but my code breaks down when big numbers are involved (I tried multiple variations with solutions involving log and power functions):</p>
  
  <p><strong>Exercise:</strong><br>
  Your task is to check wheter a given integer is a perfect power. If it is a perfect power, return a pair m and k with m^k = n as a proof. Otherwise return Nothing, Nil, null, None or your language's equivalent.</p>
  
  <p>Note: For a perfect power, there might be several pairs. For example 81 = 3^4 = 9^2, so (3,4) and (9,2) are valid solutions. However, the tests take care of this, so if a number is a perfect power, return any pair that proves it.</p>
  
  <p>The exercise uses Python 3.4.3</p>
  
  <p><strong>My code:</strong></p>
  
  <pre><code>import math
  def isPP(n):
      for i in range(2 +n%2,n,2):
              a = math.log(n,i)
              if int(a) == round(a, 1):
                  if pow(i, int(a)) == n:
                      return [i, int(a)]
      return None
  </code></pre>
  
  <p><strong>Question:</strong>
  How is it possible that I keep getting incorrect answers for bigger numbers? I read that in Python 3, all ints are treated as "long" from Python 2, i.e. they can be very large and still represented accurately. Thus, since i and int(a) are both ints, shouldn't the pow(i, int(a)) == n be assessed correctly? I'm actually baffled.</p>