Why does IEEE 754 reserve so many NaN values?

后端 未结 3 1227
清酒与你
清酒与你 2020-12-01 13:24

It seems that the IEEE 754 standard defines 16,777,214 32-bit floating point values as NaNs, or 0.4% of all possible values.

I wonder what is the rationale for reser

3条回答
  •  萌比男神i
    2020-12-01 14:26

    The IEEE-754 standard defines a NaN as a number with all ones in the exponent, and a non-zero significand. The highest-order bit in the significand specifies whether the NaN is a signaling or quiet one. The remaining bits of the significand form what is referred to as the payload of the NaN.

    Whenever one of the operands of an operation is a NaN, the result is a NaN, and the payload of the result equals the payload of one of the NaN operands. Payload preservation is important for efficiency in scientific computing, and at least one company has proposed using NaN payloads for proprietary uses.

    In more basic terms, a NaN doesn't carry any useful numerical information, and the entire 32 bits must be reserved anyway, so the unused bits in the significand would be otherwise wasted if there were not a payload defined in the standard.

提交回复
热议问题