# Computing $x_+ - x$ where $x_+$ is the rounded binary number of $x$

This question stems directly from Converting $\frac{2}{7}$ to a binary number in a $32$ bit computer

I want to check if $x_+$ (increase the value of the last bit by one unit and discard all the bits after the last bit) is closer to $x$ than $x_-$ (discard all bits after the last bit).

$x = (0.\underbrace{100100100100100100100100}_{24 \text{ bits}}10\overline{010} )_{2} \times 2^{-1}$

$x_{-} = 0.\underbrace{100100100100100100100100}_{24 \text{ bits}} \times 2^{-1}$

$x_+ = \left ((0.\underbrace{10010010010010010010010}_{23\text{ bits}}\mathbf{0})_{2} + 2^{-24} \right )\times 2^{-1} = (0.100100100100100100100101)_{2} \times 2^{-1}$

$$x-x_{-} = 0.\underbrace{0 \cdots 0 }_{24 \text{ zeros}}10\overline{010} \times 2^{-1} = 0.10\overline{010} \times 2^{-25} = \frac{2}{7} \times 2^{-25}$$

$$x_+ - x = 0.\underbrace{1}_{24\text{ th bit in }x_+}00\overline{0} \times 2^{-24} - 0.10010010\overline{010}\times 2^{-24} = 0.1101\overline{101}\times 2^{-25}$$

I don't think I did the $x_+ - x$ calculuation correctly because if I "borrow" from the the 24th bit in $x_+$, then that $24$th bit becomes a $0$. Then how we subtract that $24$th bit in $x_+$ from the $24$th bit in $x$?

• $0.1101\overline{101}_2^{\,} = 0.1\overline{101}_2^{\,} = \dfrac12+\dfrac12\times \dfrac{4+1}{4+2+1} = \dfrac67 > \dfrac27$ – Henry Sep 6 '17 at 12:48
• @Henry I just made an edit right as you commented. I think I made an error in the calculation of $x_+ - x$. Could you look at that ? – Kazi Sep 6 '17 at 12:49

For one thing, $$0.10\overline{010}_2 = 0.\overline{100}_2 = 100_2 \times 0.\overline{001}_2 = \frac 47.$$ Therefore the correct value of $x - x_-$ is $$x - x_- = \frac 47 \times 2^{-25}.$$
For another thing, the discarded bits should consistently have the same value, $0.10\overline{010} \times 2^{-25} = 0.\overline{100} \times 2^{-25},$ both when computing $x - x_-$ and when computing $x_+ - x.$ You have written $0.10\overline{010} \times 2^{-25}$ in one place and $0.10\overline{010} \times 2^{-\mathbf{24}}$ in the other. The correct value of $x_+ - x$ is $$x_+ - x = 1 \times 2^{-25} - 0.\overline{100} \times 2^{-25} = 0.\overline{011} \times 2^{-25} = \frac 37 \times 2^{-25}.$$
Checking, $$x_+ - x_- = (x_+ - x) + (x - x_-) = \frac 47 \times 2^{-25} + \frac 37 \times 2^{-25} = 2^{-25} = 2^{-24} \times 2^{-1},$$ which is precisely the value of the least significant bit of the IEEE single-precision approximation of $\frac27,$ namely the bit you set to $1$ in $x_+$ and to $0$ in $x_-.$