Skip to the workspace
Pebellslearn by building
Floating Point Math  ›  Lesson

Sign, Exponent and Fraction

Floating Point Math 12 minA floating-point number is binary scientific notation: a sign bit, an exponent that says where the point floats to, and a fraction holding the significant digits.

computer science / Sign, Exponent and Fraction

Explore each scene at your own pace.

01 · The rule

The rule

Sign, Exponent and Fraction

A single 64-bit float can hold the mass of an electron (about 9 × 10⁻³¹ kg) and the mass of the Sun (about 2 × 10³⁰ kg). No fixed position for the point could cover both. So the point is allowed to float: the number stores its digits and, separately, where the point goes. You already know this idea as scientific notation.

The rule

A float is sign × 1.fraction × 2^exponent — scientific notation in binary.

In decimal, 6,500 is written 6.5 × 10³. A float does the same in base 2. Take 6.5: in binary it is 110.1 (4 + 2 + ½). Slide the point left until one digit is in front of it:

6.5 = 110.1 (binary) = 1.101 × 2²

The standard layout (IEEE 754) stores three fields:

Part 64-bit double 32-bit float For 6.5
Sign 1 bit 1 bit 0 (positive)
Exponent 11 bits 8 bits 2
Fraction 52 bits 23 bits 101000…

Two details keep it compact. The leading 1 before the point is always 1 for normal numbers, so it is not stored; a double effectively keeps 53 significant bits. And the exponent is stored with a bias added (1023 for doubles) so negative exponents need no sign: exponent 2 is stored as 1025.

53 significant bits are about 15–17 decimal digits; a 32-bit float's 24 bits are about 7 digits. Because the number of significant bits is fixed, the gap between neighbouring floats grows as numbers get bigger. Above 2⁵³ (about 9 × 10¹⁵) a double cannot even store every whole number.

Scene 1 of 5
Hover to wake the cannons. Drag to move, or use arrow keys when focused. Press Enter to fire a shot.