Can a subtraction between two exactly represented floating point numbers with the same floating point be inexact?

社会主义新天地 提交于 2019-12-04 15:20:52

I am assuming that you want the two numbers to have the same sign. If not, the answer is "yes"; consider (-1) - nextafter(1, infinity), which works out to -2 in floating-point arithmetic with round-to-even.

Under this assumption, the answer is "no." This is (almost) a special case of Sterbenz's theorem: If x and y are floating-point numbers of opposite signs such that |y|/2 <= x <= 2|y|, then x + y is exactly-representable as a floating-point number.

I say "almost" because your statement also works for zero and subnormal numbers.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!