Re: std::max and NAN
Mycroft Holmes wrote:
does the standard say anything about the behaviour of std::min/max does on
(say, double) NAN?
I don't know the standard, but looking at the documentation for the STL, it
mentions that '<' for max/min must provide a partial ordering, which
floating point numbers that are NAN simply break.
we noticed that typical implementations of F(a,b), where F is either max
or min, is like:
(1) if (a COMPARISON b)
(2) return one of the arguments;
else
(3) return the other;
such an implementation breaks the obvious property F(a,b)==F(b,a)
in fact F(x,NAN) != F(NAN,x) because in both cases the comparison (1) is
false.
I guess that you will find more such problems if you try to sort sequences
containing NAN.
In other words, my question is: do max/min have to be consistent when one
or both arguments are NAN(s) or they are allowed to return an arbitrary
result?
I guess the behaviour is undefined, unless the standard changes the
requirements from the STL.
Uli