mahmood
mahmood

Reputation: 24705

IEEE-754 floating point number rounding mechanism

Here is the question about round and guard digits in IEEE-754 floating point number representation. According to the standard, two additional digits are reserved for calculations. Assume two digits after the point are available and

   2.3400
+  0.0256
  --------
   2.3656

Now, guard is 5 and round is 6 and since 56>50, then it is rounded to 100, therefore, the result is 2.37

However, if you don't assume the guard and round digits and only assume the additional digit is between 5 and 9, then you will round it again to 10 and the result is 2.37

So, my question is, in which situation the traditional rounding mechanism (0 to 4 are rounded to 0 and 5 to 9 are rounded to 10) fail while guard and round digits are helpful?

Upvotes: 0

Views: 5467

Answers (1)

Patricia Shanahan
Patricia Shanahan

Reputation: 26185

The problem is that the IEEE rounding rules result for 2.3650 is 2.36, not 2.37. If the exact answer is exactly half way between two representable numbers, it is rounded to the one that is even. In binary, that is the one that has a zero in the least significant bit.

If the exact answer is the slightest bit greater than 2.365, it rounds to 2.37.

The round bit distinguishes these cases.

Upvotes: 2

Related Questions