0

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 Answers1

1

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.

peterwhy
  • 22,256
  • regarding your question in the comment... differ from the next one by 0.001, this is 1/8 in binary system. Why do you show the example in base-10 system? – Max Koretskyi May 21 '16 at 18:03
  • @Maximus $1/8$ is the number $0.001_2$ written using decimal numbers, and $1/1000$ is the same fraction in binary system. So the confusion should be, why did you ask your question using partly binary and partly decimal? – peterwhy May 21 '16 at 18:40
  • I wanted to understand binary rounding using fractions. I used 1/8 instead of 1/10^11 for convinience – Max Koretskyi May 21 '16 at 18:44
  • @Maximus Yes, I understand your notation, and I didn't want to switch between decimal and binary throughout my answer. And also, I think it is more direct to see that $0.001 = 1/1000$ by positional notation. – peterwhy May 21 '16 at 18:48
  • it also just occurred to me that you were writing my fractions in binary, not decimals, so 1/10 is actually 1/2 from my example :) It seems that I understand now. Can you please show me how the same logic applies to periodic infinite fractions? We can't just take the truncated part for comparison there. – Max Koretskyi May 22 '16 at 14:13
  • 1
    @Maximus: Comparison works from the most significant bits downward (until a difference is found). As a consequence, the leftmost to-be-rounded-away digit decides most cases, the only exception being the tie case. So even with infinite digit strings, the leftmost digit decides unless it is the tie-case digit (1 in binary, 5 in decimal) and followed by all zeros. – ccorn May 22 '16 at 14:36
  • @ccorn, thanks, I still don't see though how one digit is enough for comparison, since if I take two digits, I can clearly see that the truncated part 1/16 +1/32 is more than half of $1/8$, but if it's only one, I have truncated part $1/16$ and the same number on the other side. What am I missing? – Max Koretskyi May 22 '16 at 14:50
  • 1
    @Maximus: Yes, one can see the difference better when using additional digits. It might help to consider extreme examples where the additional digits are $00\ldots0$, $00\ldots1$, or $11\ldots1$. Work out the differences and decide on the rounding direction. It turns out that the decision on the best rounding direction is only affected when the additional digits are all zero. – ccorn May 22 '16 at 14:59
  • @ccorn, thanks a lot for your help! Now the last thing I need to understand, why the truncated part should be more, less or equal to the half of the number $1/8$. – Max Koretskyi May 22 '16 at 18:10
  • 1
    @Maximus: 'cause at least one of the two possible rounded values is a least that close to the unrounded value. – ccorn May 22 '16 at 23:14
  • @peterwhy, can you please take a look at my this question? – Max Koretskyi May 25 '16 at 18:50