NaNs can potentially have many different binary representations, which can often be used to provide more information about, say, what caused the NaN. Any IEEE 32-bit float in the format of x111 1111 1xxx xxxx xxxx xxxx xxxx xxxx
is a NaN. Also, any comparison between 2 NaNs (of potentially different binary value) evaluates to false.
So given two floats:
float a = NaN1;
float b = NaN2;
Both are NaN, but may have different values for the x
bits above, what is the most correct way to compare their binary contents (i.e. check that they are the same type of NaN)?
The most obvious way to me is perform c-style casts like: *(uint32_t*)&a == *(uint32_t*)&b
however, the size of a float is not guaranteed to be 32 bits.