Computer Arithmetic

Rounding to integers with round half to even, what do 2.5 and 3.5 become?

  1. A3 and 4
  2. B2 and 4
  3. C2 and 3
Show answer and explanation

Answer: B. 2 and 4

Both are exact ties, so each rounds to the even neighbor: 2.5, halfway between 2 and 3, goes to 2; 3.5, halfway between 3 and 4, goes to 4. Always rounding ties up would give 3 and 4, summing to 7, one more than the original sum of 6, whereas rounding to even gives 2 + 4 = 6, preserving the sum. 2 and 3 result from always rounding ties down. Avoiding biased rounding error is the method's strength.

  • A. 3 and 4 result from always rounding ties up.
  • B. Correct. Both ties round to the even values 2 and 4.
  • C. 2 and 3 result from always rounding ties down.
Practice this topic Back to topic

More Computer Arithmetic questions

  1. What is the phenomenon called in which subtracting two nearly equal floating-point numbers greatly reduces the significant digits?
  2. For very large x, computing √(x + 1) − √x in floating point suffers catastrophic cancellation. Which rewrite computes it accurately?
  3. In single precision, adding 1 to 100 million (10⁸) leaves the result unchanged at 100 million. Which explains this?
  4. What is the purpose of Kahan (compensated) summation when adding many floating-point numbers?
  5. What is the advantage of computing a × b + c with an FMA (fused multiply-add) instruction?