And an old-school division trick

This is just a short note to give a division trick to go with the multiplication tricks of my previous blog post. Two divisions, r = a / b and s = c / d, can be turned into one division and five multiplies by computing the terms as

t = 1 / (b * d)
r = a * d * t
s = b * c * t

Obviously this is susceptible to various gotchas, such as b or d being zero, loss of precision, et cetera, but it’s still a cool old-school trick that has applications even to this day (as divisions are still more expensive than multiplications and often don’t pipeline well).

1 thought on “And an old-school division trick”

Leave a Reply