Re: NaNs
* Jiang:
On Jul 29, 8:35 am, "Alf P. Steinbach" <al...@start.no> wrote:
* Alan McKenney:
On Jul 28, 4:34 am, Thomas Richter <t...@math.tu-berlin.de> wrote:
Tom wrote:
[...]
More to the point, there are a very large
number of bit patterns that count as NaN.
Both Thomas and Alan and OP Tom, please note that (1) number of bitpatterns is
irrelevant, because (2) an IEEE NaN is required to be unequal to anything,
including itself.
Correct testing, after having established IEEE floating point, is
if( x != x )
{
// This is a NaN
}
Unfortunately, the above test itself will trigger the floating point
trap if x is signalling NaN.
You mean, in the context of IEEE, if the C++ implementation supports signaling
NaNs (i.e. std::numeric_limits<double>::has_signaling_NaN) and x is a signalling
NaN (e.g. an uninitialized double) and trapping on invalid operation exception
has been enabled, then the above test will invoke some handler.
I think that's /fortunate/. :-)
Also, note that the IEEE 754 standard reportedly (I only have a draft of a later
standard) says, in its ?7.1, that "The invalid operation exception is signaled
if an operand is invalid for the operation to be performed. The result, when the
exception occurs without a trap, shall be a quiet NaN (6.2) provided the
destination has a floating-point format. The invalid operations are:
1. Any operation on a signaling NaN (6.2)"
Also it is quite possible optimizer will just ignore/remove such test.
It's always possible with an error in the compiler, rendering it non-conforming.
I fail to see the relevance of that to anything.
That argument is like, don't use 'main', or don't use 'int', because there could
be an error in the compiler that, uh, well, something.
Cheers, & hth.,
- Alf
--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]