了解 IEEE 754:为什么下溢取决于不精确?

Understanding IEEE 754: why Underflow depends on Inexact?

注意:了解IEEE 754,请耐心等待。

IEEE 754-2008(添加了重点):

In addition, under default exception handling for underflow, if the rounded result is inexact — that is, it differs from what would have been computed were both exponent range and precision unbounded — the underflow flag shall be raised and the inexact (see 7.6) exception shall be signaled. If the rounded result is exact, no flag is raised and no inexact exception is signaled. This is the only case in this standard of an exception signal receiving default handling that does not raise the corresponding flag. Such an underflow signal has no observable effect under default handling.

据我了解:underflow == inexact && tiny.

简单的问题:为什么 Underflow 取决于 Inexact

即为什么如果产生了精确的次正规,那么不会引发 Underflow 异常?这种行为的动机/理由是什么?

异常通常表示无法提供理想的数学结果,它们会告知程序问题的性质。

让异常生成陷阱的一个目的是让程序可以根据程序的目的定制的方式处理这种情况。例如,一个程序可能希望通过终止当前计算序列来处理溢出。另一个程序可能希望通过重新调整操作数并记录新的比例来处理溢出,通过跟踪重新调整来有效地实现其自己的扩展指数范围。结果,另一个程序可能想要产生无穷大。因此陷阱允许自定义程序行为。

在有意义的地方,已经提供了默认结果,例如为溢出产生无穷大,并且可以接受默认结果的程序可以关闭异常陷阱。他们可能会忽略异常或在一系列计算结束时检查异常标志。

如果程序正在接受下溢的默认处理,并且出现了不正常的结果但它是准确的,则无需通知程序,因为已经提供了理想的数学结果并且程序已指示它确实如此不想对下溢采取任何特殊操作,例如重新缩放结果。如果出现下溢标志,并且程序在一系列计算结束时对其进行检查,则会错误地指示可能出现了一些不正确的结果。