How to find the difference for an infinite fraction

62 Views Asked by At

Suppose I have the number 0.101 in binary. If I want to round it to 2 places after the radix point using the algorithm rounding to the nearest I can easily find the difference between two available options (0.10 and 0.11):

0.101 - 0.10 =  0.001 = 1/8
0.101 - 0.11 = -0.001 = -1/8

However, how I would do the subtraction for the infinite fraction like 0.1:

$$ 0.1_{10} = 0.0001100110011001100110011001100110011001100110011..._2 $$

Suppose, I want to round it to 10 places after the radix point. How would I go about that?

1

There are 1 best solutions below

10
On BEST ANSWER

There is a much quicker way of applying the "round to the nearest" rule than by carrying out subtractions.

Suppose rounding down gives $a$ and rounding up gives $b$. The "round to the nearest" rule says round to whichever of $a,b$ is nearer. That is unambiguous unless the number is $\frac{a+b}{2}$ which is equidistant. We deal with that case by a tie-breaker rule (which you asked about in an earlier question).

But another way of expressing the rule is that we round up if the number is $>\frac{a+b}{2}$ and round down if it is $<\frac{a+b}{2}$.

In the case of binary fractions the number $\frac{a+b}{2}$ is the smaller number $a$ followed by a digit 1 (and nothing or only 0s thereafter). So this alternative method is much quicker. If the next digit is a 1 and there is at some point a subsequent 1, then we round up, because the number must be closer to $b$. Similarly, if the next digit is a 0 and that is not followed by an infinite string of nothing but 1s, then we round down, because the number must be closer to $a$.

You asked in the comments below for an example. For example, suppose you want to round $x=0.0110110$ to 6 places. Your choices are $a=0.011011$ or $b=0.011100$. The midpoint is $\frac{a+b}{2}=0.0110111$ which can be obtained by adding a 1 at the end of $a$. In this case $x$ has a $0$ at the end so you round it down to $a$ because we have $x<\frac{a+b}{2}$.