Real number representation in fixed point (unsigned) is as follows:
e.g.
In this case the smallest number (non zero) is \( 2^{-j} \) if \(a_i = 0, \forall i \) and \(b_1 = \dots = b_{j-1} = 0\), \(b_j = 1\).
The largest number is
i.e. \(a_k = 1\) for all \(k\), and \(b_k = 1\) for all \(k\).
If we increase \(i\) we increase the range; if we increase \(j\) we increase the precision!! There is a tradeoff!!
The solution is to let the number float!!
We can represent
(the exponent)
\(q\) is the significand \(\in [1,2)\) (a fractional value)
(fractional point)
Precision:
We can convert a binary number, e.g.
into a floating point representation:
A normalized floating point number can be formally expressed as
\(f\) is the fractional part, \(m\) is the exponent, \(b_i \in \{0,1\}\).
If \(m \in [L,U]\), \(p = n+1\),
then the smallest positive floating point number is
Largest positive normalized floating point number is
Example:
Smallest is
Largest is
If \(|x|\) is closer to zero than \(0.0625\), then it underflows to \(0\).
If \(x \notin [-28, 28]\), then \(x\) overflows to infinity.
In hardware floats are stored as follows:
First attempt:
but
is also valid!
We need a standard!!! IEEE
In memory this becomes
where \(s\) is the sign bit, c is the bias exponent, and \(f\) the significant.
We store a biased exponent in order to represent negative numbers, i.e.
bias \(= 127\)
e.g. IEEE–754 single precision (32 bits)
IEEE–754 double precision (64 bits)
Zero is represented as
\(\pm \infty \)
NaN: undefined, e.g. \(\dfrac {0}{0}\)
So \(c = (00\ldots 00)\) and \(c = (11\ldots 11)\) are reserved and thus limit the exponent range!!
e.g. for 32-bit IEEE–754:
Bias \(= 127\)
e.g. \(-67.125\)
tt in binary:
IEEE–754 single precision representation:
Smallest positive normalized number (UFL):
Largest positive normalized number (OFL) IEEE 32-bit number:
For 64-bit (double precision):
are reserved.
Smallest positive normalized FP number:
Largest positive normalized FP number:
Note again that overflow and underflow is different in floating pointer land as explained earlier: