That method is called, "Division by Invariant Multiplication".
The constants that you're seeing are actually approximates of the reciprocal.
So rather than computing:
N / D = Q
you do something like this instead:
N * (1/D) = Q
where 1/D
is a reciprocal that can be precomputed.
Fundamentally, reciprocals are imprecise unless D
is a power-of-two. So there will some round-off error involved. The +1
that you see is there to correct for the round-off error.
The most common example is division by 3:
N / 3 = (N * 0xaaaaaaab) >> 33
Where 0xaaaaaaab = 2^33 / 3 + 1
.
This approach will generalize to other divisors.