1
$\begingroup$

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?

$\endgroup$
4
  • 1
    $\begingroup$ It comes from binary gaps: see exploringbinary.com/… for a reasonable explanation $\endgroup$
    – Henry
    Commented Jan 11, 2017 at 22:39
  • $\begingroup$ I'm not quite sure what binary gaps are, I'm still new to this complicated business of numerical analysis. $\endgroup$
    – Belphegor
    Commented Jan 11, 2017 at 22:42
  • 1
    $\begingroup$ A nontechnical analogy: Suppose you are writing numbers in scientific notation, $m\times10^n$, but you are only allowed to write one digit in $m$ and one digit in $n$. Then the numbers you can write are unevenly spaced: 1, 2, 3, ..., 8, 9, 10, 20, 30, ..., 80, 90, 100, 200, 300, ... $\endgroup$
    – user856
    Commented Jan 11, 2017 at 22:43
  • 1
    $\begingroup$ The ticks on a ruler correspond to fixed point numbers, not floating point. For pictures of floating point numbers, see here, for example: blogs.mathworks.com/cleve/2014/07/07/floating-point-numbers. $\endgroup$ Commented Jan 12, 2017 at 8:25

3 Answers 3

2
$\begingroup$

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.

$\endgroup$
2
  • $\begingroup$ Can you elaborate on what you mean by "which says the LSB is 2^-51 times the MSB"? $\endgroup$
    – Belphegor
    Commented Jan 11, 2017 at 22:54
  • $\begingroup$ If the mantissa were four bits and the exponent zero, the number after $1.000_2$ would be $1.001_2$, which is $1+2^{-3}$ for a gap of $\frac 18$. The same works with $52$ bits and lots more zeros. Then if the exponent were $11_2=3_{10}$ we would have neighboring numbers be $1.000+2\cdot 2^3=8$ and $1.001_2 \cdot 2^3=9$ for a gap of $1$ instead of $\frac 18$ $\endgroup$ Commented Jan 11, 2017 at 23:17
1
$\begingroup$

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.

$\endgroup$
0
$\begingroup$

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.

$\endgroup$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .