Can two integer divisions be unified above one whole fraction line?

112 Views Asked by At

Is there a way to combine two integer divisions (i.e. division with the result rounded down to the nearest integer) into a single division operation?

What I mean is that, when working with with real (or just rational) numbers, we can combine two fractions like this:

$$\frac ab + \frac cd = \frac{ad + bc}{bd}$$

However, this does not work for truncated integer division:

$$\left\lfloor \frac 83 \right\rfloor + \left\lfloor \frac 83 \right\rfloor = 2+2 = 4 \ne \left\lfloor \frac{8 \cdot 3 + 8 \cdot 3}{3\cdot3} \right\rfloor = \left\lfloor \frac{48}{9} \right\rfloor = 5$$

I'm trying to figure out a method that would allow two such integer division to be combined into one integer division operation.

1

There are 1 best solutions below

2
On

Off the top of my head, I'd say there's no way to do what you want, at least not in any sense that would be useful for speeding up numerical calculations (which is what I assume you want to do).

You can, of course, rewrite your truncated integer division as normal division using $$\left\lfloor \frac ab \right\rfloor = \frac{a - (a \bmod b)}b,$$ where $(a \bmod b)$ denotes the remainder left when dividing $a$ by $b$, and then use the rule for combining ordinary fractions. However, in practice, calculating $(a \bmod b)$ is no easier than calculating $\lfloor \tfrac ab \rfloor$ itself, so you really gain nothing by doing so.