What is the purpose of the function ?
bool whatIsIt(double n)
{
return n == n;
}
It can be used to check every bit in n ?
I doubt that .
Any comments are appreciated.
It could be used to check if n is NaN (not a number), since NaN does not compare equal to itself.
Probably a finnicky and not entirely reliable way to do it. (see Billy's various comments) C99 and C++11 have the isnan() function.
This is specified in the C Standard in Annex F: 60559 Floating Point Arithmetic, specifically F.8.3 Relational operators:
... The statement
x != xis true ifxis aNaN... The statement
x == xis false ifxis aNaN
If __STDC_IEC_559__ is #defined, then this function will return false if n is NaN.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With