问题
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 ?
回答1:
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.
来源:https://stackoverflow.com/questions/27230129/sign-bit-of-a-nan-in-ieee-754-standard