This definition follows the NaN definition provided in IEEE 754 standard.
In IEEE 754 standard-conforming floating point storage formats, NaNs are identified by specific, pre-defined bit patterns unique to NaNs.
0x7FFFFFFF
is the largest value, that can be represented on 31 bits. In this case, it simply ignores the bit sign, because:
The sign bit does not matter.
0x7F800000
is the mask for bits of the exponential field.
For example, a bit-wise IEEE floating-point standard single precision
(32-bit) NaN would be: s111 1111 1xxx xxxx xxxx xxxx xxxx xxxx where s
is the sign (most often ignored in applications) and x is non-zero
(the value zero encodes infinities).
Where s111 1111 1xxx xxxx xxxx xxxx xxxx xxxx
with s = 0
(ignored by anding with 0x7FFFFFFF
) and x = 0
is equal to 0x7F800000
.
operator >
is used, because if any bit in the significand is set (any x
), resulting value will be greater than 0x7F800000
.
And why should it be set? Because:
The state/value of the remaining bits [...] are not defined by the standard except that they must not be all zero.
Source: NaN on Wikipedia.