In floating-point calculations, NaN is not the same as
infinity, although both are typically handled as special cases in floating-point representations of real numbers as well as in floating-point operations. An invalid operation is also not the same as an
arithmetic overflow (which might return an infinity) or an
arithmetic underflow (which would return the smallest
normal number, a
denormal number, or
zero). IEEE 754 NaNs are represented with the exponential field filled with ones and some non-zero number in the significand. A bit-wise example of a
IEEE floating-point standard single precision NaN: x11111111axxxxxxxxxxxxxxxxxxxxxx. x = undefined. If a = 1, it is a
quiet NaN, otherwise it is a
signalling NaN. A NaN does not compare equal to any floating-point number or NaN, even if the latter has an identical representation. One can therefore test whether a variable has a NaN value by comparing it to itself (i.e. if x != x then x is NaN). In the IEEE floating-point standard, arithmetic operations involving NaN always produce NaN, allowing the value to propagate through a calculation so that errors can be detected early. In the proposed
IEEE 754r revision of that standard the same rule applies, except that a few anomalous functions (such as the
maxnum function, which returns the maximum of two operands which are expected to be numbers) favour numbers—if just one of the operands is a NaN then the value of the other operand is returned. A different approach has been implemented in the
NaN 'toolbox' for
GNU Octave and
MATLAB. In that toolbox, NaNs are
assumed to represent
missing values and so the statistical functions ignore NaNs in the data instead of propagating them. Every computation in the NaN toolbox is based on the data values only, which can be useful if it is known that NaNs cannot be produced by errors.