Mycroft Holmes
2007-11-26 10:25:22 UTC
hi,
does the standard say anything about the behaviour of std::min/max does on
(say, double) NAN?
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.
also it should hold that "min(a,b) LESS-OR-EQUAL max(a,b)"
where LESS-OR-EQUAL is a relaxed comparison operator so that NAN is
LESS-OR-EQUAL to NAN.
but again, this axiom is easily broken: the following implementation
(which -I think- is implemented in VC8 stl)
min(a,b) := a<b ? a : b
max(a,b) := a<b ? b : a
violates it, as min(x,NAN)==NAN, but max(x,NAN)==x
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?
thanks in advance for the answer
-MH
does the standard say anything about the behaviour of std::min/max does on
(say, double) NAN?
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.
also it should hold that "min(a,b) LESS-OR-EQUAL max(a,b)"
where LESS-OR-EQUAL is a relaxed comparison operator so that NAN is
LESS-OR-EQUAL to NAN.
but again, this axiom is easily broken: the following implementation
(which -I think- is implemented in VC8 stl)
min(a,b) := a<b ? a : b
max(a,b) := a<b ? b : a
violates it, as min(x,NAN)==NAN, but max(x,NAN)==x
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?
thanks in advance for the answer
-MH