title: C++ - How to correctly cast double to int
body: <p>I'm currently writing a program that needs to take the floor of a square root. Since the value I'm taking the square root of is positive, I just cast it to int. So say for the following example:</p>
  
  <pre><code>int i = 16;
  int j = std::sqrt(i)
  </code></pre>
  
  <p>j should be 4.</p>
  
  <p>I am wondering though, is it possible that sqrt returns 3.9999999991 instead of 4.000000001 or whatever, and the result of j is 3? Is there rules defining floating point behaviour? How can I properly convert this to an int?</p>