IEEE 754-2008 Floating-Point
# ================================================================
# IEEE 32-bit floating-point standard
#
# sign (1 bit)
# | exponent (8 bits)
# | | mantissa/fraction (23 bits)
# | | |
# v v v
# +---+----------+-------------------------+
# 0 00000000 00000000000000000000000
# +---+----------+-------------------------+
# 31 30 23 22 0 <- bits
#
# ================================================================
#
# IEEE 64-bit word floating-standard
#
# sign (1 bit)
# | exponent (11 bits)
# | | mantissa/fraction (52 bits)
# | | |
# v v v
# +---+-------------+-------------------------------+
# 0 00000000000 000000000000.....000000000000
# +---+-------------+-------------------------------+
# 63 62 52 51 0 <- bits
#
# ================================================================
# Note: there is a 128-bit floating-point standard (not show here)
Unpack and Reassemble Floating-Point Numbers
Unpack the floating-point number into integers (sign, exponent, and mantissa).
Once unpacked, the actual value of a normal floating-point number is
reconstructed using this mathematical formula:
| IEEE 754 |
| Bits | Exponent Bias |
| 32 | 127 |
| 64 | 1023 |
value = (-1)sign * (1 + (mantissa / 2bits_in_mantissa)) * 2exponent-bias
The 1 + accounts for the "implicit leading bit" that IEEE 754 drops to
save space.