Not a Number: How computing systems handle the impossible and the undefined
In short: In the world of digital logic, some operations simply do not yield a numerical result. When a calculation hits a dead end, like the square root of a negative number, computers return NaN. This special value acts as a placeholder, allowing errors to propagate through complex chains of mathematical operations.
Introduced by the IEEE 754 standard in 1985, NaN—short for Not a Number—provides a formal way for computing systems to represent undefined or invalid values. Before this standard, programmers often relied on arbitrary placeholders like -99999999 to signal missing data, a practice that lacked consistency. Today, NaN serves as a robust mechanism for handling non-finite quantities, distinct from infinity, which arises from different mathematical conditions.
There are two primary types of NaNs: quiet NaNs (qNaNs) and signaling NaNs (sNaNs). Quiet NaNs are designed to propagate through most arithmetic operations without triggering exceptions, allowing developers to detect errors at the end of a long sequence of calculations rather than testing every intermediate step. Conversely, signaling NaNs are intended to raise an invalid-operation exception when consumed, which can be useful for advanced tasks like identifying uninitialized memory or mixing symbolic and numerical computation.
The behavior of NaN challenges standard mathematical logic. For instance, the trichotomy of real numbers—where one value must be less than, equal to, or greater than another—fails when NaN is involved. Instead, comparisons involving NaN are considered unordered. Furthermore, while most operations with a NaN operand return a NaN, some functions can mask this result. For example, a calculation like x^0 may return 1 even if x is NaN, potentially obscuring an error. Consequently, relying solely on the final output can be misleading, and developers often need to check status flags to ensure that invalid operations were not silently ignored during processing.
Opens the Intellect+ feed with this card first. Swipe up for the next one.
Sources
- Summary by Intellect · source: NaN
- Also: Wikidata — Nan · CC0
To cite this card, link to https://intellectplus.co.uk/app/places-nan.
How we source, check and correct cards: Editorial standards.
General information, not professional advice. Spotted an error? Flag the card or see corrections and complaints.
Intellect Plus is a visual educational discovery platform for exploring fascinating facts and ideas. Brain Food, Not Brain Rot. What is Intellect Plus?
Related
More in Technical geography · More in Countries & Cities · Latest · A–Z · All topics