Re: NaNs
* Alberto Ganesh Barbati:
Alf P. Steinbach ha scritto:
* Jiang:
On Jul 29, 8:35 am, "Alf P. Steinbach" <al...@start.no> wrote:
* Alan McKenney:
Correct testing, after having established IEEE floating point, is
if( x != x )
{
// This is a NaN
}
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.
The fact is that an aggressive optimizer might replace "x == x" with
true and "x != x" with false even if that may be produce incorrect
results for float and double. This is very common.
I'm shocked. I truly am. It's *very common* for C++ compilers to produce
incorrect machine code?
Yes, I'm aware you wrote this.
But please pardon me, it's a bit hard to swallow. When I first learned
programming compilers were infallible, any error would be the programmer's and
not the compiler's. And now at least C++ compilers have devolved to the opposite
end, now just heaps of erronous dirty hacks thrown together in haphazard fashion
by amateurs, very common with incorrect machine code generation, yes?
So the test "x != x",
while being theoretically correct, it's not practically useful.
I'm wondering, besides comparisions not working correctly, what other IEEE 754
features do, very commonly, work incorrectly when the compiler's standard
library implementation defines is_iec559?
Or, from another point of view, are there any features that can be relied on?
And that's why isnan() is good to have.
Hm, well, yes, I'm shocked -- *very common* with incorrect machine code! Grumble.
Perhaps this is the end of C++.
Cheers,
- Alf (hoping someone may clear this up)
--
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! ]