What is the rationale for all comparisons returning false for IEEE754 NaN values?

后端 未结 11 1976
耶瑟儿~
耶瑟儿~ 2020-11-21 07:04

Why do comparisons of NaN values behave differently from all other values? That is, all comparisons with the operators ==, <=, >=, <, > where one or both values is NaN

11条回答
  •  春和景丽
    2020-11-21 07:19

    I don't know the design rationale, but here's an excerpt from the IEEE 754-1985 standard:

    "It shall be possible to compare floating-point numbers in all supported formats, even if the operands' formats differ. Comparisons are exact and never overflow nor underflow. Four mutually exclusive relations are possible: less than, equal, greater than, and unordered. The last case arises when at least one operand is NaN. Every NaN shall compare unordered with everything, including itself."

提交回复
热议问题