[Solved] Divide without divide c++ [closed]


Compare Xs1 * m2 with Ys2 * m1. If X > Y, then s1 / m1 > s2 / m2.

No division is required to do the comparison.

The caveat to this solution is that s1, s2, m1, and m2 should all have the same sign, and m1 and m2 should be non-zero.


Let’s assume all the values are positive integers (hence, greater than 0). Consequently m1 * m2 is positive as well. Let z be the number such that:

z + (s1 / m1) = s2 / m2

By multiplying by m1 * m2 on both sides, we get:

z’ + (s1 * m2) = s2 * m1z’z × (m1 * m2)

Since z and z’ have the same sign, the relational order of s1 / m1 and s1 / m2 is the same as the relational order of s1 * m2 and s2 * m1.

2

solved Divide without divide c++ [closed]