What is result of -5%3 ? How modulo work with negative numbers ? — Code Oven
% sign is helpful to get remainder after division. -5 is dividend and 3 is divisor in our question. In plain English, % sign tells us how far multiple of divisor, which is equal or smaller than dividend, from dividend is.
There are two closed multiple of divisor (3) to dividend (5) is -3 and -6. -6 is smaller than -3. How far -6 is from -5 ? 1 unit. So answer of -5 % 3 would be 1.
I hope above explanation makes sense. I appreciate your support. Please follow and subscribe me on Medium and Youtube if you found this explanation helpful.
Originally published at http://punitvara.me on March 9, 2023.