Why is NaN not equal to NaN
조회 수: 18 (최근 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!