简体   繁体   English

为什么零不是次正规数?

[英]Why is zero not a subnormal number?

The IEEE-754 standard defines subnormal numbers such that the two zeros are explicitly excluded. IEEE-754 标准定义次正规数,以便明确排除两个零。 What's the rationale for this decision, and does this mean that the performance penalty for subnormals does not apply to zero?这个决定的理由是什么,这是否意味着次正规的性能惩罚不适用于零?

First of all, it's important to recognize that IEEE-754 is a standard for the behavior of conforming implementations.首先,重要的是要认识到 IEEE-754 是一致实现行为的标准。 It talks about "what", not "how".它谈论的是“什么”,而不是“如何”。 It is not a guide on how to effectively implement that behavior, in software or in hardware.它不是关于如何在软件或硬件中有效实现该行为的指南。 The fact that zero has the bit pattern and semantics of a subnormal is interesting and clearly not an accident but is not what the standard is here to talk about .零具有次正规的位模式和语义这一事实很有趣显然不是偶然的,但不是这里要讨论的标准

Second of all, a bit of history: subnormals are one of the weirder aspects of IEEE-754.其次,回顾一下历史:次正规是 IEEE-754 中比较奇怪的方面之一。 Plenty of previous approaches to floating point didn't support them.许多以前的浮点方法都不支持它们。 To this day, the majority of 754 implementations either allow them to be toggled off, support them only through software fallbacks, or don't support them at all.直到今天,大多数 754 实现要么允许关闭它们,要么仅通过软件回退支持它们,要么根本不支持它们。

Subnormals were, and are, seen as a "last line of defense": You wouldn't generally intentionally use them as inputs, but having them available as outputs helps with the robustness of FP-using algorithms.次正规函数过去和现在都被视为“最后一道防线”:您通常不会故意将它们用作输入,但将它们用作输出有助于提高使用 FP 的算法的稳健性。 Sterbenz's theorem (you can exactly subtract any two FP numbers which differ by less than a factor of two) is a good example of this. Sterbenz 定理(您可以精确地减去相差小于两倍的任何两个 FP 数)就是一个很好的例子。 But the difficulty of efficiently implementing subnormal arithmetic was recognized at the time.但当时认识到有效实施次正规算术的困难。

Needless to say, the number zero is pretty common.不用说,数字零很常见。 Operations involving zero are not done using the code/circuitry which supports subnormals, because that would be slow, and it's trivially easy to special-case zero inputs instead.涉及零的操作不会使用支持次正规的代码/电路来完成,因为那样会很慢,而且用特殊情况来代替零输入非常容易。

So, to sum up: Zero was not described as a "subnormal number" because the important practical aspects of subnormal numbers (ie the slowness) do not apply to it.因此,总结一下:零没有被描述为“次正规数”,因为次正规数的重要实际方面(即慢度)不适用于它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM