# How to determine the set of real numbers corresponding to a given floating point number?

Let's say we consider IEEE 754 double precision floating-point numbers, and we use RNTE - Round To Nearest, Ties to Even - rounding. I know that the RNTE rounding works this way: given two consecutive floating-point numbers, a and b, and a real number x,

• if a <= x < (a+b)/2, x gets translated to a
• if (a+b)/2 < x <= b, x gets translated to b
• if x = (a+b)/2, x gets translated to the number with an even significand between a and b

For example, I want to know which are the real numbers that are "mapped" to 1, where 1 is a floating-point number. How should I proceed? I thought that I must consider both the cases where 1 is a and where 1 is b in the above definition, and so consider both the previous and the next floating-point number. Is it correct? Is there a simpler way?

• Stricto sensu, there is no answer to this question. Because computers cannot represent real numbers, so "x gets translated to ..." is meaningless, no such translation process exists. Aug 8 at 8:40
• Also note that the floating-point numbers do not follow a regular arithmetic progression, so one can question the "nearest neighbor" rule. Aug 8 at 8:42

Today, my professor explained how to sove this problem. Since I think that it might be useful to other users, I'll post here the answer.

Given a floating-point number $$f$$ in a particular encoding (for example IEEE 754 single/double precision), we want to know which subset of real numbers corresponds to $$f$$, that is to say which real numbers gets rounded to f when converted to the same encoding. We're using RNTE (Round To Nearest, Ties to Even) rounding.

We represent the encoding as a quadruple $$\mathbb{F}(\beta,t,M_1,M_2)$$, where $$\beta$$ is the base, $$t$$ is the number of significand digits after the point and $$M_1$$,$$M_2$$ are the lower and upper bounds for the exponent range, respectively.

For example, let's choose to work with IEEE 754 double precision numbers, which we can denote as $$\mathbb{F}(2,52,-1023,1024)$$.

Let $$f = 17 = (10001)_{2} = 1.\overbrace{00010...0}^\text{52 digits} \times 2^{4} \in \mathbb{F}$$.

We have to determine the predecessor and the successor of $$f$$, both of which are in $$\mathbb{F}$$. Let's call them $$a$$ and $$b$$, respectively. In order to do this, we have to find the distance between $$a$$ and $$f$$ and between $$f$$ and $$b$$. We know that $$17 \in [16, 32] = [2^{4},2^{5}]$$, so we can use the formula $$y-x=\beta^{p-t}$$ to get those distances, where $$x,y \in [\beta^{p},\beta^{p+1}]$$, $$\beta=2$$, $$p=4$$, $$p+1=5$$ and $$t=52$$.

So, $$a = 17 - 2^{4-52} = 17 - 2^{-48}$$,

and $$b = 17 + 2^{4-52} = 17 + 2^{-48}$$

Now we can apply the RNTE rounding, which states that a real number $$x$$ is rounded to its nearest number in $$\mathbb{F}$$ and, if there are two candidates, it chooses the one with an even mantissa (or significand). The latter case means that $$x$$ is the midpoint between two consecutive numbers in $$\mathbb{F}$$.

The midpoint between $$a$$ and $$17$$ is $$x_1 = 17 - \frac{1}{2} 2^{-48} = 17 - 2^{-49}$$,

the midpoint between $$17$$ and $$b$$ is $$x_2 = 17 + \frac{1}{2} 2^{-48} = 17 + 2^{-49}$$

Each real number between $$x_1$$ and $$x_2$$ gets rounded to $$17$$, including $$x_1$$ and $$x_2$$, because 17 has an even mantissa in our representation. So the answer is $$\{x \in \mathbb{R} \mid 17 - 2^{-49} \leq x \leq 17 + 2^{-49}\}$$.

• Just saw this. Looked remarkably like my answer except your professor missed the case where f is a power of two. Apr 9 at 22:48

The powers of two are more interesting than most other numbers.

Assume you are using double precision IEEE 754 format floating point numbers. Let $$u = 2^{-52}$$, Then the next floating point number larger than 1 is $$1+u$$, and the next floating point number smaller than 1 is $$1 - u/2$$.

A real number x is rounded to 1 if $$1-u/4 ≤ x ≤ 1+u/2$$. For any floating-point number f with $$1 < f < 2$$, x is rounded to f if $$f - u/2 ≤ x ≤ f + u/2$$ if the last bit of f is even, and if $$f - u/2 < x < f + u/2$$ if the last bit of f is odd.

Numbers x with $$f - u/2 < x < f + u/2$$ are always rounded to f, because f is the nearest floating point number. For the numbers $$x = f ± u/2$$, $$f$$ and $$f ± u$$ are equally far away, so the round-to-even rule decides.

• Thank you for the answer. Could you please tell me what is the general rule being applied here? How can I solve this problem for any given floating-point number? One more thing: I read a solved excercise where $f = 1+2^{-52}$, and the answer is $1+2^{-53} < x < 1+2^{-52}+2^{-53}$, I don't understand how this is achieved. Nov 13, 2020 at 0:58
• Since f = 1 + 2^-52, that's exactly the f - u/2 < x < f + u/2 from my answer. Nov 15, 2020 at 12:24

If the mantissa is not all ones, the next floating-point number is $$1$$ ulp more.
• E.g. $$1.1000_b\times 2^7\to1.1001_b\times 2^7$$ ($$192_d\to200_d$$), the difference is $$2^{7-4}=8$$.
• E.g. $$1.1111_b\times 2^7\to1.0000_b\times 2^8$$ ($$248_d\to256_d$$), the difference is $$2^{7+1}-(2^{7+1}-2^{7-4})=8$$.