Why does floating point numbers have uneven spacing on the number line?

2.1k Views Asked by At

Can someone explain to me what it means for floating point numbers to have "uneven" spacing on a number line? As I visualize this, all I see is evenly spacing out floating point numbers.

When I google for an explanation, most of them just say "floating point numbers have uneven spacing", but none of them explain why or how?

When I look at a ruler for example, everything is evenly spaced out so where does the "uneven" spacing thing come in and exactly mean visually?

3

There are 3 best solutions below

2
On BEST ANSWER

The uneven spacing comes from the exponent. There are a fixed number of bits in the mantissa for a given storage format. For example, in IEEE $64$ bit storage there are $52$ bits for the mantissa, which says the LSB is $2^{-51}$ times the MSB. If the exponent is zero (after allowing for the offset) the difference between two neighboring floats will be $2^{-51}$. If the exponent is $20$, the difference between two neighboring floats will be $2^{-31}$ because the mantissa is multiplied by $2^{20}$. They are (approximately) separated by the same fractional amount, but by different absolute amounts.

0
On

Floating point numbers are represented in the form $A \cdot 2^B$, where $A$ and $B$ are both integers. This means that the difference between a floating point number and the "next" (the one you get increasing $A$ by $1$) is $2^B$; thus the smaller $B$, the closer the spacing.

0
On

Since there is a constant number of mantissa bits, you have the same number of floating point numbers as in the interval from $1$ to $2$ also in the interval from $2$ to $4$ and from $4$ to $8$, and generally in any interval $[2^n, 2^{n+1})$. As the interval length increases, so does the spacing between the floating point numbers.