# What is meant by "uneven spacing" on number line when dealing with floating point numbers in computers?

I read some examples online on this subject, but none of them really gave an explanation. When I visualize the number line all I can see is evenly spaced numbers, I'm not grasping the notation of "uneven spacing" when It comes to plotting the floating point values from a machine's perspective. Perhaps I am thinking about this too literally.

Let's look at a single-precision floating point number (as specified by IEEE 754). It is made up of 32 bits. Therefore, there are exactly $2^{32}$ floating point numbers that dots the number line.

What does it mean when we say that the floating point numbers are "unevenly" distributed on the number line? It means that they are not uniformly distributed. But why?

Well, let's consider the case where these numbers are distributed uniformly on the number line. Then there's some constant finite gap between successive numbers, $\Delta$. Since there are $2^{32}$ points on this line, then these uniformly distributed numbers span an interval of $\Delta \times 2^{32}$ width.

How big is $2^{32}$? Well, it's about 4 billion. Do you see the problem with uniformly distributed representations of numbers? If you want to even be able to represent the number $\pm 2$ billion in your uniform system, then you need to make sure that both $-2 \times 10^9$ and $2 \times 10^9$ are within your representable interval. Therefore, we need $\Delta \times 2^{32} \ge 4 \times 10^9$, so that we must space our numbers around $\Delta \approx 1$ apart. But if $\Delta \approx 1$, how are you going to represent both $1$ and $0.5$ precisely? Their difference is smaller than the gap!

Herein lies the rationale for having non-uniformly distributed representations such as floating point numbers. Uniformly distributed representations (or fixed-point numbers) cannot represent both big numbers and small numbers in a "good-enough" manner.

let consider a simple decimal system in which precession = 3, lower exponent = -3 & upper exponent = 3. so in order to call it uniform, number line should have a equal gaps between consecutive numbers.

case 1: $$x_1 = 1.31*10^2, x_2= 1.32*10^2$$ $$\therefore \Delta x =0.01*10^2$$

case 2: $$x_1 = 1.31*10^{-2}, x_2 = 1.32*10^{-2}$$ $$\therefore \Delta x = 0.01*10^{-2}$$

since $$\Delta x$$ in case 1 is not equal to case 2, we can say that floating point numbers are not uniformly distributed.

Positive floating point numbers are encoded as something like

$Mantissa * 2^{Exponent-Constant}.$

Where $Mantissa$ and $Exponent$ are naturals, for example respectively 24bits and 7bits scalars (32bits single precision).

The 'spacing' between consecutive values depend on the exponent, it is not constant.

(Actual floating point numbers are a bit more complex with encoding for infinites, tricks around zero...)

Take a C++ compiler. Start with double x = 1.0 and double y = 1e100.

Now try out various values z, and find for which z you find that x+z != x or y+z != y. What is the smallest z where 1.0 + z != 1.0 and the smallest z where 1e100 + z != 1e100?