Why does IEEE 754 reserve so many NaN values?

后端 未结 3 1238
清酒与你
清酒与你 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条回答
  •  误落风尘
    2020-12-01 14:16

    There is likewise a payload for 64 bit floating point numbers as well, with ~10^15 possible values. Unfortunately, implementations diverge as to how the payload should be transferred between 32 and 64 bit floating point numbers and back again, i.e. whether you preserve the most significant or least significant bits. Since payload treatment is machine specific, you need different code to deal with payloads on different machines.

    I wouldn't worry too much about which NaN payload is propagated after a binary operation. NaNs are exceptional values that occur with low probability, and the probability of getting 2 of them is unlikely.

提交回复
热议问题