floating point product expansion equivalence

后端 未结 3 1226
抹茶落季
抹茶落季 2021-01-18 10:11

In IEEE 754 floating point, it is possible that

a*(b-c) != a*b-a*c // a, b, c double

So expansion of a product is not guaranteed to be equa

3条回答
  •  滥情空心
    2021-01-18 10:42

    IEEE 754 doesn't delve too much into language details. In particular, details like "compile time" aren't specified. That doesn't even make sense for some languages.

    The easiest case to understand is when you have an intermediate infinity. Assume that sum(b)==INF, barely, but a is 0.5. The result a*sum(b) is still INF. However, by multiplying first, the subsequent addition no longer overflows.

提交回复
热议问题