Rounding - should I compare truncated sum with the number added to make least bigger number

299 Views Asked by At

Suppose I have a number in binary: $$ 0.11111 = 0 + \frac{1}{2} + \frac{1}{4} + \frac{1}{8} + \frac{1}{16} + \frac{1}{32} $$

I want to round it to 3 significant digits after the radix point. So, I need to come up with the least bigger and the least less number than the number with 3 radix points. To find the bigger number, I add $1/8$, to find the less number, I simply truncate the $1/16+1/32$. Now, deciding to which number round comes down to defining whether $1/8$ is bigger than $1/16+1/32$. It's less, so I round down. Is this correct?

If it's correct, than I don't understand when the number added to find least bigger number can be less than the truncated sum, which will force me to round up? And when will they be equal, so that I'll have to apply tie-breaking rule?

1

There are 1 best solutions below

11
On BEST ANSWER

If you round any binary number to three digits after radix point, then each possible number, e.g. $0.000, 0.001, 0.010, 0.011$, etc), differ from the next one by $0.001$. If the truncated part is less than half of that, i.e. $0.0001$, then the number is rounded down: $$0.10001 \approx 0.100$$

If the truncated part is more than half of $0.001$, then the number is rounded up: $$0.10011 \approx 0.101$$

If the truncated part is exactly half of $0.001$, then the tie-breaking rule applies.


So for this example,

$$0.11111 = \frac1{10}+\frac1{100}+\frac1{1000}+\frac1{10000} + \frac1{100000}$$

The truncated part is $0.00011 = \frac{11}{100000}$, which is more than half of $0.001 = \frac{1}{1000}$, and so the number is rounded up.