符合IEEE 754标准的NAN的符号位 [英] sign bit of a NAN in IEEE 754 standard

查看:285
本文介绍了符合IEEE 754标准的NAN的符号位的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想执行一个浮点单精度加法运算,其中

A = + infinity(7F800000)
B = - infinity(FF800000)

请问结果(A + B)是+ NAN还是-NAN?另外一个相关的问题是: p>

如果NAN通过算术运算传播,我们得到qNAN。
鉴于sNAN代表无效的异常操作。
因此,上述操作将导致一个sNAN。
我的理解是否正确?

解决方案

IEEE 754标准没有规定你应用NaN产生NaN的操作。唯一的建议,并不总是遵循,如果结果是NaN,因为至少有一个操作数是,那么结果应该有一个相同的代表NaN操作数。

从非NaN操作数生成NaN可能是中断控制流的一个机会(例如,使用陷阱),这取决于系统的设置方式。如果主机系统没有立即中断控制流程,产生的NaN就是一个安静的NaN。

信号NaNs可以用来填充应该考虑的内存未初始化:这将导致立即异常,而不是传播一个NaN值。算术操作返回一个信号NaN是没有意义的,因为异常的原因是当前的操作(这个操作发信号给NaN,NaN又被忽略或者根据系统的设置而作用)。返回一个信号NaN会使它看起来好像下一个操作是异常的原因。

NaN有自己的维基百科页面有很多信息。


I want to perform a floating point single precision addition operation in which

A = + infinity ( 7F800000) B = - infinity ( FF800000)

Will the result(A+B) be +NAN or -NAN ?

another related question :

We get qNAN if NAN propagates through the arithmetic operation. Whereas sNAN represents an invalid exception operation. So, the above operation will result into a sNAN. Is my understanding correct ?

解决方案

The IEEE 754 standard does not specify which representation of NaN you get when you apply an operation that produces a NaN. The only recommendation, not always followed, is that if the result is NaN because at least one of the operands is, then the result should have an identical representation to one of the NaN operands.

Producing a NaN from non-NaN operands may be an opportunity to interrupt the control flow (for instance, with a trap), depending how your system is set up. If the host system is not set up to interrupt the control flow immediately, the produced NaN is a quiet NaN.

Signaling NaNs are useful to fill up memory that should be considered uninitialized: this would cause an immediate exception instead of propagating a NaN value. It would not make sense for an arithmetic operation to return a signaling NaN, because the cause of the exception is the current operation (which signals the NaN, which in turn is either ignored or acted upon depending how the system is set up). Returning a signaling NaN would make it look as if the next operation is the cause of the exception.

NaN has its own Wikipedia page with a lot of information.

这篇关于符合IEEE 754标准的NAN的符号位的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆