title: Can I rely on this to judge a square number in C++?
body: <p>Can I rely on  </p>
  
  <pre><code>sqrt((float)a)*sqrt((float)a)==a
  </code></pre>
  
  <p>or  </p>
  
  <pre><code>(int)sqrt((float)a)*(int)sqrt((float)a)==a
  </code></pre>
  
  <p>to check whether a number is a perfect square? Why or why not?<br>
  <code>int a</code> is the number to be judged. I'm using Visual Studio 2005.</p>
  
  <p><strong>Edit:</strong> Thanks for all these rapid answers. I see that I can't rely on float type comparison. (If I wrote as above, will the last <code>a</code> be cast to float implicitly?) If I do it like  </p>
  
  <pre><code>(int)sqrt((float)a)*(int)sqrt((float)a) - a &lt; e  
  </code></pre>
  
  <p>How small should I take that <code>e</code> value?</p>
  
  <p><strong>Edit2:</strong> Hey, why don't we leave the comparison part aside, and decide whether the <code>(int)</code> is necessary? As I see, with it, the difference might be great for squares; but without it, the difference might be small for non-squares. Perhaps neither will do. :-(</p>