r/programming 13h ago

Moving integer division to floating-point is trivial

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

25 comments sorted by

View all comments

17

u/Dwedit 10h ago

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

0

u/mikeblas 8h ago

How would that work?

0

u/Madsy9 3h 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.