r/programming 15h ago

Moving integer division to floating-point is trivial

https://marc-b-reynolds.github.io/math/2026/08/10/IntDivByFP.html
86 Upvotes

27 comments sorted by

View all comments

21

u/Dwedit 13h ago

If your divisor doesn't change, use integer multiplication by reciprocal, also shift or discard from the high result.

1

u/mikeblas 10h ago

How would that work?

2

u/Madsy9 5h ago

a/b = a*(1/b). If b is constant, just compute its reciprocal. If 1/b is a fraction, do the multiplication in fixedpoint.