The significant bits in a NaN (except the leading bit distinguishing between quiet and signalling NaN) are called “payload”.
This is what Perplexity.ai gave me for How do NaN payloads work in IEEE 754?:
=============================================
NaN payloads in IEEE 754 provide additional bits in the significand field of NaN values for diagnostic or application-specific data, beyond just signaling invalid operations. en.wikipedia
NaN Structure
NaNs share the all-1s exponent with infinities but have a non-zero significand (fraction/mantissa).
- Sign bit: Ignored or application-defined (often 0).
- Leading significand bit: Distinguishes types.
- Quiet NaN (qNaN): MSB=1 (propagates silently).
- Signaling NaN (sNaN): MSB=0 (may raise exceptions if enabled).
- Payload: Remaining significand bits (e.g., 22 bits for single precision binary32, 51 for binary64 double). stackoverflow
| Format | Total Bits | Exponent | Sign + Type Bit | Payload Bits |
|---|---|---|---|---|
| binary32 | 32 | 8 | 2 | 22 |
| binary64 | 64 | 11 | 2 | 51 |
| binary128 | 128 | 15 | 2 | 111 |
Example binary32 qNaN: 0 11111111 1xxxxxxxxxxxxxxx (payload in x’s). en.wikipedia
Payload Behavior
- Propagation: Operations with NaN return NaN, typically copying the input NaN’s payload (or preferring one if multiple). discourse.llvm
- Ordering: NaNs sort after numbers; among NaNs, by payload (lesser payload < greater in IEEE 754-2008). en.wikipedia
- Uses: Diagnostic codes (e.g., error origins), NaN-boxing (type-tagged non-floats in payloads, as in JavaScript engines), or proprietary data. dan.corlan
Standard Operations (IEEE 754-2008/2019)
IEEE 754-2019 recommends getPayload, setPayload, setPayloadSignaling for payload access (required for new implementations). englishwiki.en-us.nina
| Operation | Behavior |
|---|---|
| qNaN op anything | qNaN (payload preserved) |
| sNaN op non-NaN | qNaN (if no exception) |
| sNaN op sNaN | qNaN |
| Comparison with NaN | False (except != self) |
Payloads enhance NaN utility without altering core semantics, ensuring vast NaN space (~0.4% of values) isn’t wasted. Implementations vary (e.g., x86 may embed instruction addresses). stackoverflow
Edited: As for 0**0 result, according to englishwiki.en-us.nina link above, also found elsewhere, the standard (IEEE, I presume) provides several power functions with different expected results:
- The standard
powfunction and the integer exponentpownfunction define0**0,1**(±∞), and(±∞)**0as 1. - The
powrfunction defines all three indeterminate forms as invalid operations and so returns NaN.