Integer division through multiplication by reciprocal

135 Views Asked by At

Please help me to understand (prove) why the following statement is true.

For any natural number $w > 0$ and divisor $b \in \left[ 1, 2^w \right)$, if we define a natural number $inv(b)$ such that

$$ 2^w - b \leq b \cdot \mathrm{inv}(b) < 2^w $$

then for any natural dividend $a \in \left[ 0, 2^w \right)$ and quotient $q = \left \lfloor a/b \right \rfloor$ it follows that $$ q - 1 \leq \left \lfloor \frac{a \cdot inv(b)}{2^w} \right \rfloor \leq q. $$

1

There are 1 best solutions below

4
On BEST ANSWER

Since everything in sight is positive we have, from your first inequality, that

$$\frac{a}{b} - \frac{a}{2^w} \leq \frac{a\cdot \mathrm{inv}(b)}{2^w} < \frac{a}{b}.$$

Also note that if $x\leq y$, $\lfloor x\rfloor \leq \lfloor y \rfloor$.

Can you take it from here?