Why is NaN not equal to NaN
10 ビュー (過去 30 日間)
古いコメントを表示
Why is this not true?
NaN==NaN
ans =
0
0 件のコメント
採用された回答
Cedric
2013 年 1 月 16 日
編集済み: Cedric
2013 年 1 月 16 日
Most times, you don't want this test to return true indeed. Imagine testing a==b and having a true result when both a and b are undefined; this would make little sense. It is the same with NaN.
While it is not the original question, note that you can test equality assuming NaN 's are equal:
But with that you usually want to test if "behaviors" are the same (and not equality per se), e.g. if two functions return the same number or both NaN do something, else do something else.
その他の回答 (1 件)
Matt J
2013 年 1 月 16 日
編集済み: Matt J
2013 年 1 月 16 日
Because equality is a notion applied to numbers. How can 2 things be equal when they are not numbers?
7 件のコメント
math man
2021 年 9 月 17 日
You might wonder, though, why NaN ~= NaN returns true?
That is, if they are not numbers why are they compared in this case to give a misleading result?
参考
カテゴリ
Help Center および File Exchange で Logical についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!