没有扩展精度 FPU 的数值陷阱
Monniaux 的优秀文章,“陷阱验证浮点算术”,给出了意外数值行为的示例。然而,大多数示例依赖于扩展精度 FPU 或扩展精度运算(例如乘法累加)。除了有符号零和涉及 NaN 的比较之外,当扩展精度硬件被禁用时,还有什么令人惊讶的数值行为的好例子吗?
Monniaux's excellent article, "The Pitfalls of Verifying Floating Point Arithmetic", gives examples of unexpected numerical behavior. However, most of the examples depend on extended precision FPUs or extended precision operations (e.g. multiply-accumulate). Besides signed zero and comparisons involving NaN are there any good examples of surprising numerical behavior when extend precision hardware is disabled?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
一个经常让程序员感到惊讶的例子是
x + 1 == x
。在单精度浮点中,对于小至2^25
的x
来说也是如此,因为尾数的精度有限。当在模拟中以小时间步长增加时间值时,通常会出现这种情况。 类似问题影响了爱国者导弹。An example that is often surprising to programmers is when
x + 1 == x
. In single precision floating point, this is true forx
as small as2^25
because of the limited precision of the mantissa. This often comes up when incrementing time values in a simulation by a small timestep. A similar problem affected the Patriot missile.