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

后端 未结 11 2135
耶瑟儿~
耶瑟儿~ 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:28

    The over-simplified answer is that a NaN has no numeric value, so there is nothing in it to compare to anything else.

    You might consider testing for and replacing your NaNs with +INF if you want them to act like +INF.

提交回复
热议问题