NaN and maximum/minimum?

Probably a stupid question… but why is:

julia> maximum([1,NaN]) 
julia> minimum([1,NaN])
julia> 1 > NaN
julia> 1 < NaN

…I have a rectangular matrix of (possibly complex) vectors, of which 2 elements have zero length – so I replace them with NaN for plotting reasons. Then I want to find the non-NaN element in this matrix of vectors with the largest real part.

I found the explanation interesting.

To get your results you will have to filter or replace the NaN values.
maximum(filter(!isnan,a)) #allocates
maximum(x->isnan(x) ? -Inf : x,a) #non-allocating

1 Like

NaN is specified by the IEEE Standard so that any comparison with a NaN results is false (including NaN==NaN).

Since 1 <= NaN === false and NaN <= 1 === false, minmax(1, NaN) == (NaN, NaN). That’s why the minimum and maximum functions behave as you noted.


Thanks. I tried to use missing instead, but the plot routine complained that it was not a Float. Not that I know whether that had worked better with maximum, though…