← 🔢 Number Representation & Computer Arithmetic
Subtopic 9 of 9

4.9Precision & rounding

The idea

Floating-point numbers are approximations. Rounding and limited bits mean the usual rules of arithmetic do not always hold.

Think of it like this: A ruler that only has 1 mm marks: you cannot measure 0.3 mm exactly, and adding many small measurements can lose them.

Why it exists

Understanding rounding explains subtle bugs and some GATE trick questions.

How it works

  1. Many decimals (0.1) have no exact binary form.
  2. To add, the smaller exponent is aligned, shifting out low bits.
  3. Adding a tiny number to a huge one can lose the tiny one entirely.
  4. Hence floating-point addition is not associative.

Worked example: (1e20 + −1e20) + 1 vs 1e20 + (−1e20 + 1)

First gives 1, second gives 0 (the 1 is lost inside −1e20).

Now play with it

  • →Read the live results of each experiment; they are computed by your browser.
0.1 + 0.2 (double)0.30000000000000004
0.1 and 0.2 have no exact binary form, so the sum is slightly off.
(1e20 + −1e20) + 1 (double)1
Cancels first, then adds 1: exactly 1.
1e20 + (−1e20 + 1) (double)0
The 1 is absorbed by −1e20 (not enough mantissa bits): result 0. Not associative!
16777216 + 1 (single)16777216
2^24: single precision has 24 significant bits, so +1 is lost.
16777216 + 2 (single)16777218
+2 is representable at this magnitude (spacing is 2).

Check yourself

Is floating-point addition associative?

Remember: Floating point is approximate: order of operations matters.
Exam notes (the dense version)

Mantissa has hidden leading 1. Floating-point addition: align exponents (shift smaller), add, normalise, round. Not associative!

Previous year questions: Number Representation & Computer Arithmetic (19)

PYQs are grouped by topic, so this is the full set for Number Representation & Computer Arithmetic; try the ones that match this subtopic. Open all 19 on the topic page.