What is overflow and underflow in floating point
<p>I feel I don't really understand the concept of <code>overflow</code> and <code>underflow</code>. I'm asking this question to clarify this. I need to understand it at its most basic level with bits. Let's work with the simplified floating point representation of <code>1</code> byte - <code>1</code> bit sign, <code>3</code> bits exponent and <code>4</code> bits mantissa:</p>

<pre><code>0 000 0000
</code></pre>

<p>The max exponent we can store is <code>111_2=7</code> minus the bias <code>K=2^2-1=3</code> which gives <code>4</code>, and it's reserved for <code>Infinity</code> and <code>NaN</code>. The exponent for max number is <code>3</code>, which is <code>110</code> under offset binary.</p>

<p>So the bit pattern for max number is:</p>

<pre><code>0 110 1111 // positive
1 110 1111 // negative
</code></pre>

<p>When the exponent is zero, the number is subnormal and has implicit <code>0</code> instead of <code>1</code>. So the bit pattern for min number is:</p>

<pre><code>0 000 0001 // positive
1 000 0001 // negative
</code></pre>

<p>I've found these descriptions for single-precision floating point:</p>

<pre><code>Negative numbers less than −(2−2−23) × 2127 (negative overflow)
Negative numbers greater than −2−149 (negative underflow)
Positive numbers less than 2−149 (positive underflow)
Positive numbers greater than (2−2−23) × 2127 (positive overflow)
</code></pre>

<p>Out of them I understand only <strong>positive overflow</strong> which results in <code>+Infinity</code>, and the example would be like this:</p>

<pre><code>0 110 1111 + 0 110 1111 = 0 111 0000 
</code></pre>

<p>Can anyone please demonstrate the three other cases for overflow and underflow using the bit patterns I outlined above?</p>