我一直在阅读论文每个计算机科学家应该知道的浮点运算.
我已经看过各种ULP计算,并且在对减法的讨论出现之前我觉得我非常理解它.
Take another example: 10.1 - 9.93. This
becomes
x = 1.01 × 10^1
y = 0.99 × 10^1
x - y = .02 × 10^1
The correct answer is .17, so the computed difference is off by 30 ulps
and is wrong in every digit!
Run Code Online (Sandbox Code Playgroud)
为什么这个30ulps而不是0.3?因为ulp肯定是0.01x10 ^ 1,换句话说是0.1.误差为0.03,即0.3 ulps.
正确的答案写在评论中,但我会把它写下来作为答案,这样它就不会隐藏在评论噪音中。
\n\n基本上x - y = .02 \xc3\x97 10^1被归一化为2.00 \xc3\x97 10^-1,这意味着 ULP 现在是此归一化表示中的最小值:0.01 \xc3\x97 10^-1。
因此错误是
\n\n0.03 / [(0.01 \xc3\x97 10^-1)/ULP] = 30 ULP\nRun Code Online (Sandbox Code Playgroud)\n