#1,097 – Summary of how Floating Point Numbers Are Stored in .NET

Here’s a complete summary of how 32-bit and 64-bit floating point numbers are represented in .NET, including special values.  For more background, look here and here.

Floating point numbers are stored in .NET according to the IEEE 754 standard:

  • Normalized values (1.bb x 2^bb)
    • Sign bit – positive/negative
    • Mantissa – normalized binary number, does not store leading 1  (23 or 52 bits)
    • Exponent – biased, add 127 (or 1023) to exponent before storing  (8 or 11 bits)
  • Subnormal numbers
    • Sign bit – positive/negative
    • Mantissa – non-normalized, no implied leading 1  (23 or 52 bits)
    • Exponent – 0
  • Positive/negative zero
    • Sign bit – positive/negative
    • Mantissa – 0
    • Exponent – 0
  • Positive/negative infinity
    • Sign bit – positive/negative
    • Mantissa – 0
    • Exponent – FF (hex) or 7FF (hex)
  • NaN
    • Sign bit – not defined (implementation dependent)
    • Mantissa – some non-zero value
    • Exponent – FF (hex) or 7FF (hex)

Ranges for (normalized) numbers represented as 32- and 64-bit floating point numbers:

  • 32-bit float: -3.4 x 10^38 to 3.4 x 10^38
  • 64-bit double: -1.7 x 10^308 to 1.7 x 10^308