language-icon Old Web
English
Sign In

NaN

In computing, NaN, standing for not a number, is a numeric data type value representing an undefined or unrepresentable value, especially in floating-point arithmetic. Systematic use of NaNs was introduced by the IEEE 754 floating-point standard in 1985, along with the representation of other non-finite quantities such as infinities. In computing, NaN, standing for not a number, is a numeric data type value representing an undefined or unrepresentable value, especially in floating-point arithmetic. Systematic use of NaNs was introduced by the IEEE 754 floating-point standard in 1985, along with the representation of other non-finite quantities such as infinities. For example, 0/0 is undefined as a real number, and is therefore represented by NaN. The square root of a negative number is an imaginary number and cannot be represented as a real number, so is represented by NaN. NaNs may also be used to represent missing values in computations. Two separate kinds of NaNs are provided, termed quiet NaNs and signaling NaNs. Quiet NaNs are used to propagate errors resulting from invalid operations or values. Signaling NaNs can support advanced features such as mixing numerical and symbolic computation or other extensions to basic floating-point arithmetic. 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 encoded with the exponent field filled with ones (like infinity values), and some non-zero number in the significand field (to make them distinct from infinity values); this allows the definition of multiple distinct NaN values, depending on which bits are set in the significand field, but also on the value of the leading sign bit (but applications are not required to provide distinct semantics for those distinct NaN values). 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 the x sequence represents a non-zero number (the value zero encodes infinities). The first bit from x is used to determine the type of NaN: 'quiet NaN' or 'signaling NaN'. The remaining bits encode a payload (most often ignored in applications). Floating-point operations other than ordered comparisons normally propagate a quiet NaN (qNaN). Most floating-point operations on a signaling NaN (sNaN) signal the invalid operation exception; the default exception action is then the same as for qNaN operands and they produce a qNaN if producing a floating-point result. The propagation of quiet NaNs through arithmetic operations allows errors to be detected at the end of a sequence of operations without extensive testing during intermediate stages. For example, if one starts with a NaN and adds 1 five times in a row, each addition results in a NaN, but there is no need to check each calculation because one can just note that the final result is NaN. However, depending on the language and the function, NaNs can silently be removed from a chain of calculations where one calculation in the chain would give a constant result for all other floating-point values. For example, the calculation x^0, may produce the result 1, even where x is NaN, so checking only the final result would obscure the fact that a calculation before the x^0 resulted in NaN. In general, then, a later test for a set invalid flag is needed to detect all cases where NaNs are introduced (see Function definition below for further details). In section 6.2 of the current IEEE 754-2008 standard, there are two anomalous functions (the maxNum and minNum functions, which return the maximum of two operands that are expected to be numbers) that favor numbers — if just one of the operands is a NaN then the value of the other operand is returned. For the next revision of the IEEE 754 standard, it is planned to replace these functions as they are not associative (when a signaling NaN appears in an operand).

[ "Algorithm", "Arithmetic", "Binary scaling", "Programming language", "Decimal floating point" ]
Parent Topic
Child Topic
    No Parent Topic