title: Strange behaviour when comparing cast float to zero
body: <p>I'm currently trying to learn about floating point representation in depth, so I played around a bit. While doing so, I stumbled on some strange behaviour; I can't really work out what's happening, and I'd be very grateful for some insight. Apologies if this has been answered, I found it quite hard to google!</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;cmath&gt;
  using namespace std;
  
  int main(){
  
    float minVal = pow(2,-149); // set to smallest float possible
    
    float nextCheck = static_cast&lt;float&gt;(minVal/2.0f); // divide by two
    bool isZero = (static_cast&lt;float&gt;(minVal/2.0f) == 0.0f); // this evaluates to false
    bool isZero2 = (nextCheck == 0.0f); // this evaluates to true
    cout &lt;&lt; nextCheck &lt;&lt; " " &lt;&lt; isZero &lt;&lt; " " &lt;&lt; isZero2 &lt;&lt; endl;
    // this outputs 0 0 1
    
    return 0;
  
  }
  </code></pre>
  
  <p>Essentially what's happening is:</p>
  
  <ul>
  <li>I set minVal to be the smallest float that can be represented using
  single precision </li>
  <li>Dividing by 2 should yield 0 -- we're at the minimum</li>
  <li>Indeed, isZero2 does return true, but isZero returns false.</li>
  </ul>
  
  <p>What's going on -- I would have thought them to be identical? Is the compiler trying to be clever, saying that dividing any number cannot possibly yield zero?</p>
  
  <p>Thanks for your help!</p>