Smallest integer not representable in single precision floating point
floating-point, precision
Solution
How did we figure out that we use 2^(23+1) + 1
IEEE floating point represents normalised numbers in the following form.
(-1)s2(e – e0)(1+(m/2M))
Where:
- s is the sign bit, with a value of 0 or 1.
- e is the exponent field, with a value between 1 and 2E-2 where E is the number of exponent bits (values of 0 and 2E-1 are used for subnormals and infinites/NaNs).
- e0 is the exponent bias. It essentially sets the overall range of the floating point number.
- M is the number of mantissa bits.
- m is the mantissa with a value between 0 and 2M-1
zero can't be represented by this format, but it can be resented as a subnormal, so that is ok. All non-zero integers that can be represented are represented in the normalized format.
To convert a positive integer i to floating point we use.
e = floor(log2(i)) + e0
m = ((i/2(e – e0))-1) 2M
If i < 2M+1 then (e − e0) ≤ M so m is an integer. Therefore i is representable.
If i = 2M+1 then (e − e0) = M+1 and m = 0. Therefore i is representable.
If i = 2M+1 + 1 then (e − e0) = M+1 and m = ½. Therefore i is not representable.
Problem
So I know that the smallest positive integer not representable by a single precision floating point is 2^(23+1) + 1 = 16,777,217. How did we figure out that we use 2^(23+1) + 1. I understand that there is an implied 1, along with 23 being the number of bits represented in the mantissa but why does this work?