CS With NehalCS With Nehal

Floating Point Representation Simulator

Store numbers as a two's complement mantissa and exponent, normalise them and see rounding errors, plus IEEE 754 32-bit and 64-bit.

Format

Value = mantissa × 2^exponent. Both are two's complement; the mantissa has an implied binary point after its first (sign) bit.

Mantissa bits
Exponent bits
−1 . ½ ¼ ⅛…
Mantissa place values
-8 to 7
Exponent range
127
Largest positive
0.001953125
Smallest normalised positive
More mantissa bits give more precision. More exponent bits give a bigger range. With a fixed total, gaining one means losing the other.

Denary → floating point

  1. 1. 5.75 = 0.71875 × 2^3
  2. 2. Mantissa 0.71875 → 0.1011100
  3. 3. Exponent 3 → 0011

Mantissa

0
1
0
1
1
1
0
0

Exponent

0
0
1
1
5.75
Stored value
0
Rounding error

Floating point → denary

Click bits to change them.

Mantissa (0.1011100)

−1
2⁻1
2⁻2
2⁻3
2⁻4
2⁻5
2⁻6
2⁻7

Exponent (3)

−8
4
2
1

0.71875 × 2^3 = 5.75

Normalised: the first two mantissa bits differ (01), so no precision is wasted.

About This Simulation

This floating point simulator shows how real numbers are stored as a mantissa and an exponent. In the A Level format both are two's complement: convert denary numbers, normalise binary values step by step and see the rounding error. A second mode shows IEEE 754 single precision as used by real computers.

Features

  • Mantissa from 2 to 16 bits and exponent from 2 to 8 bits
  • Denary to floating point with each step and the rounding error
  • Clickable mantissa and exponent bits with place values
  • Normalisation check and step-by-step normalising
  • Range and precision for the chosen format
  • IEEE 754 32-bit and 64-bit: sign, biased exponent, fraction and the exact stored value

Topics covered

  • Floating Point Representation
  • Mantissa and Exponent
  • Normalisation
  • Precision vs Range
  • Rounding Errors
  • IEEE 754

Explanation

Floating point stores a number as mantissa × 2^exponent, like scientific notation in binary. The mantissa holds the significant digits and the exponent says where the binary point goes. In the Cambridge A Level format, the mantissa is a two's complement fraction with the binary point after the sign bit, and the exponent is a two's complement integer.

How it works

  1. Mantissa place values are −1, ½, ¼, ⅛, …, so 0.1011 means ½ + ⅛ + 1⁄16 = 0.6875.
  2. Value = mantissa × 2^exponent. With mantissa 0.1011100 and exponent 3, the value is 0.71875 × 8 = 5.75.
  3. A normalised mantissa starts with 01 (positive) or 10 (negative), so no bits are wasted on leading zeros or ones.
  4. To normalise, shift the mantissa left until the first two bits differ, subtracting 1 from the exponent for each shift.
  5. More mantissa bits give greater precision; more exponent bits give a greater range. Numbers that need more bits than the mantissa has are rounded, giving a rounding error.

Why it matters

Floating point representation and normalisation are A Level (9618 Paper 3) topics. Understanding rounding errors explains why 0.1 + 0.2 is not exactly 0.3 in most programming languages and why money should not be stored as floating point.

Frequently Asked Questions

Why are floating point numbers normalised?

Normalisation gives the most precision for a given number of mantissa bits and ensures each number has only one representation.

How do you tell if a mantissa is normalised?

A positive normalised mantissa starts 0.1 and a negative one starts 1.0: the first two bits are different.

What is the trade-off between mantissa and exponent bits?

With a fixed total, more mantissa bits increase precision but reduce range, and more exponent bits increase range but reduce precision.

Why can't 0.1 be stored exactly?

0.1 has an infinitely repeating binary fraction (0.000110011…), so it must be cut off and rounded to fit the mantissa.

Related Simulations