The "Trick" that Compilers Use for Long Division - Computerphile
Computerphile
May 26, 2026
Computers process addition and multiplication in a single clock cycle, but division is computationally expensive, requiring dozens of steps. To optimize performance, compilers replace division by constants with a clever mathematical shortcut: multiplying by a specific fraction and then shifting the bits, effectively bypassing the slow division hardware entirely.
Key insight: Dividing by a constant like 3 is so slow that compilers actually rewrite your code to multiply by a massive pre-calculated number (like 2.8 billion) and then shift the result, which is significantly faster than performing actual division.