Search code examples
floating-pointnanieee-754

IEEE 754 identity laws: Literal meaning and value-changing optimizations


The IEEE 754-2008 standard says for expressions like 0 + x and 1 * x that the identity property may be applied (§ 10.4):

Applying the identity property 1 × x when x is not a signaling NaN and the result has the same exponent as x.

I'm wondering what does "the result has the same exponent as x" mean?


Solution

  • I think they mean the exponent field of the binary representation.

    Multiplying by 1 doesn't change the exponent even for a QNaN, even if the significand (NaN payload) changes. All NaNs have the same all-ones exponent encoding. (Infinity is all-ones exponent with significand=0; the entire rest of the coding space for that exponent value is spent on NaN payloads which basically nobody uses.)

    For any non-NaN, it's trivially true that the exponent field doesn't change when you multiply by 1. Neither does the significand or sign bit. (IIRC, 1.0 * -0.0 = -0.0).