Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Matlab: 0 < NaN = 0

Tags:

nan

matlab

I've been really tripped out by this error.

Is this really expected from MATLAB or is it a bug?

Why wouldn't 0 < NaN produce an error?

like image 471
Zaki Mohzani Avatar asked Dec 04 '22 02:12

Zaki Mohzani


2 Answers

According to MathWorks' documentation on NaN, the only logical operator that does not return false with NaN is ~= (not equals).

This makes sense logically, though: if something is "not a number", it cannot (should not) be compared to numbers. NaN doesn't equal anything.

Further, this is an IEEE standard: NaN is unordered and thusly cannot be compared. It doesn't work in any IEEE 754-compliant language.

In short, it's not a bug.

like image 152
erip Avatar answered Dec 29 '22 07:12

erip


NaN has special properties. Math operations performed with NaN result in a NaN (x+NaN = NaN). Comparisons to a NaN return false.

http://blogs.mathworks.com/seth/2009/02/04/how-do-i-test-for-nan-in-my-model/

like image 34
Joe Urc Avatar answered Dec 29 '22 08:12

Joe Urc