Why does 9.0 + 4.53 + 4.53 yield 9.05 when β = 10 and p = 3?

I'm reading this paragraph in What Every Computer Scientist Should Know About Floating-Point Arithmetic:

(6)

(Suppose the triangle is very flat; that is, a ≈ b + c. Then s ≈ a, and the term (s - a) in formula (6) subtracts two nearby numbers, one of which may have rounding error. For example, if a = 9.0, b = c = 4.53, the correct value of s is 9.03 and A is 2.342.... Even though the computed value of s (9.05) is in error by only 2 ulps, the computed value of A is 3.04, an error of 70 ulps.

from: http://docs.oracle.com/cd/E19957-01/806-3568/ncg_goldberg.html#1403

I wonder why (a+b+c)/2 is equal to 9.05, where a = 9.0 , and b = c = 4.53 ?

I suppose a hardware it may concern will calculate a+b first, which results 13.53 , rounded to 13.5 . Then c will be added to 13.5 , giving us 18.03 , which is eventually rounded to 18.0 . Finally, 18.0 is divided by 2 . This yields 9.00 , and is given to variable s . It is assumed that this hardware has at least one guard digit.

So where is wrong?


If they did b + c = 9.06 first, then added a + 9.06 = 18.06 , rounded that to 18.1 they'd get to 9.05 .

I guess this detail is not that important, the point is that with only three significant digits,

  • you'll end with 9.00 or 9.05 , but not with the correct 9.03 (even though that number could be represented)
  • every additional operation you do introduces more inaccuracy, so that the end result can be off by far more than just the three digit limitation ( 3.04 vs 2.342... , which does not get even the first digit right)
  • 链接地址: http://www.djcxy.com/p/85624.html

    上一篇: 浮点相对误差范围,需要澄清

    下一篇: 为什么9.0 + 4.53 + 4.53在β= 10和p = 3时产量为9.05?