How IEEE 754 double-precision works

JavaScript numbers are 64-bit IEEE 754 "double precision" floats. The 64 bits are divided into three fields:

  • Sign (1 bit) — 0 for positive, 1 for negative
  • Exponent (11 bits) — stored with a bias of 1023. Raw value 0 means denormalized; 2047 means Infinity or NaN.
  • Mantissa (52 bits) — the fractional part. There's an implicit leading 1 (for normal numbers), so you get 53 bits of precision total.

The value is: ±1.mantissa × 2(exponent - 1023)

This is why 0.1 + 0.2 !== 0.3 — 0.1 and 0.2 can't be represented exactly in binary, so the sum accumulates a tiny rounding error. Try clicking "0.1 + 0.2" and "0.3" to compare their bits.