title: Is it safe to compare a float and an int in Java?
body: <p>Is it safe to compare a float and an integer like this?</p>
  
  <pre><code>private static void foo(float n) {
      if (n &gt;= 1 || n &lt;= 0) {
        // code 
      } 
  }
  </code></pre>
  
  <p>According to the <a href="http://docs.oracle.com/javase/specs/jls/se7/html/jls-5.html#jls-5.6.2" rel="nofollow noreferrer">JLS (5.6.2. Binary Numeric Promotion)</a> if one of the parameters is <code>float</code>, the other is converted to <code>float</code> before comparison.
  But as far as I understand, such a comparison will return true if the converted float is binary identical to the original float. How can we ensure it?</p>