title: (int) Math.sqrt(n) much slower than (int) Math.floor(Math.sqrt(n))
body: <p>I was looking at my code, hoping to improve its performance and then i saw this:</p>
  
  <pre><code>int sqrt = (int) Math.floor(Math.sqrt(n));
  </code></pre>
  
  <p>Oh, ok, i don't really need the call to Math.floor, as casting the double returned from Math.sqrt(n) will be effectively flooring the number too (as sqrt will never return a negative number). So i went and dropped the call to Math.floor:</p>
  
  <pre><code>int sqrt = (int) Math.sqrt(n)
  </code></pre>
  
  <p>sat back and complacently watched the code run and perform roughly 10% ! worse than its previous version. This came to me as a shock. Any ideas anyone?</p>
  
  <p>Math.floor javadocs: "Returns the largest (closest to positive infinity) double value that is less than or equal to the argument and is equal to a mathematical integer."</p>
  
  <p><strong>EDIT</strong>
  in my case <strong>n</strong> is a long. Any chance cast-floor-sqrt would ever produce a different int than cast-sqrt? I personally can't see why it ever would... all numbers involved are positive.</p>