title: Truncation error in taking square root in python
body: <p>I'm trying to use Fermat's factorization method
  <a href="http://en.wikipedia.org/wiki/Fermat%27s_factorization_method" rel="nofollow">http://en.wikipedia.org/wiki/Fermat%27s_factorization_method</a>
  to factor a RSA exercise with <code>n = pq = 17113393402958118715148546526344227921781458985077442510282855190555424972779474416264134494113</code></p>
  
  <p>Here's my python code:</p>
  
  <pre><code>    def isSquare(x):
        return pow(int(sqrt(x)),2) - x == 0
  
  n = 17113393402958118715148546526344227921781458985077442510282855190555424972779474416264134494113  
  
  for i in xrange(10):
    print isSquare(n+i*i)
  </code></pre>
  
  <p>When I execute, it prints all <code>True</code>s, which isn't correct. I think it's truncation error in python. How should I deal with it? Thanks.</p>
  
  <pre><code>def isqrt(n):
      x = n
      y = (x + n // x) // 2
      while y &lt; x:
          x = y
          y = (x + n // x) // 2
      return x
  
  print isqrt(99999999999**2)
  for i in xrange(130000,140000):
    if isqrt(n + i*i) ** 2 == n + i*i:
      print isqrt(n + i*i)
  print "done"
  </code></pre>