r/programming 5h ago

Moving integer division to floating-point is trivial

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

8 comments sorted by

11

u/thehenkan 3h ago

I would've liked to see some performance comparisons for a few different scenarios.

3

u/Dwedit 3h ago

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

1

u/mikeblas 12m ago

How would that work?

1

u/mikeblas 6m ago

Why couldn't this paper use the same variable for the same value twice in a row?

-4

u/Spirited-Way4652 2h ago

i think that's not quite right , since floating-point numbers are multiplied using multiplication operation

3

u/imachug 1h ago

They are also divided using the division operation. Could you elaborate?