I have a code piece that I'm analysing but I don't understand this lines:
double level = 0;
...
if (!(level == level) && !(level < level) && !(level > level))
exit(0);
I think it is about double comparison subject. Any idea what it is?
I have a code piece that I'm analysing but I don't understand this lines:
double level = 0;
...
if (!(level == level) && !(level < level) && !(level > level))
exit(0);
I think it is about double comparison subject. Any idea what it is?
It's a rather over-engineered test for not a number (NaN).
NaN is a special floating point value. (Not all floating point types have it but the most common one - IEEE754 - does.)
It's defined to compare not equal to all other numbers, including itself.
It's also defined to be not greater than or not less than any other number, including itself. (Although this subsequent test is superfluous).
From C++11, you can use std::isnan(level)
instead. Before then, my favourite way of testing was to use the considerably simpler expression level != level
.