Figuring out round, floor and ceil with integer division

1 · Clément Bœsch · Nov. 25, 2022, 8:38 a.m.
Lately I've been transforming a float based algorithm to integers in order to make it bit-exact. Preserving the precision as best as possible was way more challenging than I initially though, which forced me to go deep down the rabbit hole. During the process I realized I had many wrong assumptions about integer divisions, and also discovered some remarkably useful mathematical properties. This story is about a journey into figuring out equivalent functions to round(a/b), floor(a/b) and ceil(a/b...