r/programming • u/mttd • Aug 11 '26
Moving integer division to floating-point is trivial
https://marc-b-reynolds.github.io/math/2026/08/10/IntDivByFP.html
112
Upvotes
r/programming • u/mttd • Aug 11 '26
View all comments
6
u/ReDucTor Aug 11 '26
Assuming your divisor doesnt change much you could use something like libdivide, this will end up with just a few simple ALU operations (multiply, shift, add/sub)
Using a float or double for this you will likely lose all benefit from the overhead of converting to a double and back again (converting back is the hard part).
You might get more throughput but heavily dependent on the CPU and the ports needed.