title: Exact representation of integers in floating points
body: <p>I am trying to understand the representation of integers in floating point format.</p>
  
  <p>Since the IEEE floating point format have only 23 bits for mantissa, i expect any integer which is greater than 1&lt;&lt;22 to be only a approx representation. This is not what i am observing in g++</p>
  
  <p>both of the cout below prints the same value 33554432. </p>
  
  <p>Since the mantissa part is the one which is responsible for the precision how can we be able to represent (store) exact number which need more than 23 bits to be stored accurately. </p>
  
  <pre><code>void floating_point_precision(){
    cout&lt;&lt; setprecision(10);
    float fp = (1&lt;&lt;25);
    cout&lt;&lt; fp &lt;&lt;endl;
    cout&lt;&lt; (1&lt;&lt;25) &lt;&lt;endl;
  }
  </code></pre>
  
  <p>As a followup based on the answer below why is the following code not executing "Not Equal" even though the print of both the fp,i are different.</p>
  
  <pre><code>void floating_point_precision(){
    cout&lt;&lt; setprecision(10);
    float fp = ((1&lt;&lt;25)+1);
    cout&lt;&lt; fp &lt;&lt;endl;
    int i = ((1&lt;&lt;25)+1)  ;
    cout&lt;&lt; i &lt;&lt;endl;
    if(i != fp)
      cout&lt;&lt; "Not equal" &lt;&lt;endl;
  }
  </code></pre>