A new algorithm makes signed 64-bit floor division up to 20% faster

A new faster algorithm to compute 64-bit signed floor division

Floor division rounds toward negative infinity and is often what you want for timestamps and repeating patterns, yet mainstream compilers don't provide it and common implementations are slow. Ben Joffe introduces a new multiply-shift method for compile-time constant divisors that benchmarks 10–20% faster on ARM and 5–10% faster on x86 for most 64-bit divisors. He also notes that Hacker's Delight barely covers the topic and that a prominent library shipped a buggy version for years.

Floor division can be much faster than you probably realise.

More from this day

2026-10-29