What a Computer Does to a Number
The Gap to the Next Representable Number, and How to Compute It
Last timeWhere the Point Floats
Representable values are evenly spaced between one power of two and the next, so the gap is two to the exponent minus 52, which is derived here and then used on a tenth and on a counter that stops.
Where the gap comes from
A 64 bit real is a sign, a 53 bit significand whose leading bit is implied, and
an exponent. Hold the exponent still at some value and ask what values are
available. The significand runs over every whole multiple of from
up to , which is . Multiplying by
, the available values are
$$
and the difference between any two neighbours in that list is $2^{e} \cdot
2^{-52} = 2^{e-52}$. It is the same difference every time, because the only
thing changing is a whole number of units in the significand. So inside the
interval from to , which is conventionally called a binade,
the representable values sit on an even grid, and the grid spacing is
.
- the gap: the distance from x to the representable value immediately above it
- the value in question, anything other than zero
- the exponent of the binade x lies in, which is the largest power of two not above the size of x
- the number of fraction bits, which is 52 for the 64 bit form and 23 for the 32 bit form
The step everyone skips when doing this by hand is the floor. For the
logarithm is , and the floor of that is , not .
Rounding a negative logarithm towards zero gives the wrong binade and a gap
twice as large as the real one. The check that costs nothing is to confirm that
afterwards: and ,
and , so is right.
It doubles, and it doubles all at once
The practical consequence of the shape is the discontinuity rather than the
trend. Just below in the 32 bit form the exponent is 23 and the gap is
. Just above the exponent is 24 and the gap is
. Nothing gradual happens between those two statements. One
representable value has a neighbour one away and the very next one has a
neighbour two away.
The lesson stops here
4 more paragraphs to go
You have read the opening. The rest of the argument, the problems that check whether it landed, and the lines worth keeping at the end all come with a plan.
The first lesson of every course in the library reads the whole way through, free, so you can see exactly what the rest of them are.
See the planThe contentsThis is the reading half
Starting the course gives you your own copy of it. Every idea on every page has problems standing under it, marked with a reason rather than a tick, and any sentence you do not believe can be opened and argued with. None of that can happen on a page nobody owns.
The contents