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

后端 未结 11 1948
耶瑟儿~
耶瑟儿~ 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条回答
  •  -上瘾入骨i
    2020-11-21 07:22

    Very short answer:

    Because the following: nan / nan = 1 must NOT hold. Otherwise inf/inf would be 1.

    (Therefore nan can not be equal to nan. As for > or <, if nan would respect any order relation in a set satisfying the Archimedean property, we would have again nan / nan = 1 at the limit).

提交回复
热议问题