# Algorithm to compute a div d and a mod d

I wanted to ask here a question about a simple algoirhtm to compute a div d and a mod d. My doubt specifically depend on negative numbers:

Doesn't the algorithm get wrong results for $$-4$$ and $$2$$ for instance, since the reminder of that division is 0? In this case the algorithm should give a quotient of $$2$$, But i image it should be $$-2$$, am i right?

• (I think you want $\Omega(|a|/d)$ instead of $O(|a|/d)$). Nov 25 '21 at 9:37