(resend to list... sorry, Ken)
On 2012-10-02 15:25, Ken Turkowski wrote:
> Similarly
> if (!(a <= a))
> is not the same as
> if (a > a)
> when one of the operands is a Nan.
Correct; I would expect the results of the above to be true and false,
respectively, because any ordering comparison with NaN gives false (even
the same NaN compared against itself). However...
> Note that
> if (!(a == a))
> is not the same as
> if (a != a)
> when one of the arguments is a NaN.
...really? According to Wikipedia[1], "every NaN compares unequal to
every value, including itself", therefore I would expect both of the
above to be true for 'a' being a NaN.
I can confirm this on x86_64 with 'a' being a double, and have no reason
to expect the result would be different on any platform form any IEEE
754 conforming data type.
Also, while 'a > b' != '!(a <= b)' is reasonably understood in the
presence of values that cannot be ordered with respect to each other, I
would find any instance of '!(a == b)' != 'a != b' to be surprising,
regardless of whether or not b is an alias for a.
1:
http://en.wikipedia.org/wiki/Floating_point#IEEE_754:_floating_point_in_modern_computers
--
Matthew