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

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

    I'm guessing that NaN (Not A Number) means exactly that: This is not a number and thus comparing it does not really make sense.

    It's a bit like arithmetic in SQL with null operands: They all result in null.

    The comparisons for floating point numbers compare numeric values. Thus, they can't be used for non numeric values. NaN therefore cannot be compared in a numeric sense.

提交回复
热议问题