title: How (and why) does "Python compute square roots of perfect squares exactly"?
body: <p>This <em>amazing</em> <a href="https://codegolf.stackexchange.com/a/88796/85527">code golf answer</a> to <em>Is this number Loeschian?</em> in its entirety:</p>
  <blockquote>
  <h2>Python, 49 bytes</h2>
  
  <p><code>lambda n:0in[(n-3*i*i+0j)**.5%1for i in range(n)]</code></p>
  <p>Uses the equivalent quadratic form given on OEIS of <code>n == 3*i*i+j*j</code>.  Check whether <code>n-3*i*i</code> is a perfect square for any <code>i</code> by taking its square root and checking if it's an integer, i.e. equals 0 modulo 1. <strong>Note that Python computes square roots of perfect squares exactly, without floating point error.</strong> The <code>+0j</code> makes it a complex number to avoid an error on the square root of a negative.</p>
  </blockquote>
  <p>How does Python do this? Does <code>**.5</code> &quot;detect&quot; that a given number is a perfect square somehow? Is this only reliable for integer input or will it work on floats up to some size as well?</p>
  <p>I've also added a parenthetical <em>Why?</em> to the question; is this something that programmers rely upon? Is it for speed? Does it come with a cost?</p>