我正在逻辑模拟器中设计 FPU,我需要知道哪些操作会生成两种 NaN(安静:qNaN 和信号:sNaN)
编辑:我发现像 0*infinity 这样的算术运算总是生成 qNaN(来源:http://www.savrola.com/resources/NaN.html)。然而,我仍然不知道的是,除了将变量设置为 sNaN 的位模式之外,是否还有其他方法可以获得 sNaN。
最佳答案
我假设您对要模拟的任何浮点规范都有某种教科书或规范。在那里寻找定义。
对于更一般的内容,您可以阅读:http://en.wikipedia.org/wiki/NaN
以下是维基百科关于 sNaN 的说法:
Signaling NaN
Signaling NaNs, or sNaNs, are special forms of a NaN that when consumed by most operations should raise an invalid exception and then, if appropriate, be "quieted" into a qNaN that may then propagate. They were introduced in IEEE 754. There have been several ideas for how these might be used
- Filling uninitialized memory with signaling NaNs would produce an invalid exception if the data is used before it is initialized
- Using an sNaN as a placeholder for a more complicated object, such as:
- A representation of a number that has underflowed
- A representation of a number that has overflowed
- Number in a higher precision format
- A complex number
关于floating-point - 哪些浮点运算会产生安静/信号 NaN?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27680322/