Take for example C
#include <stdio.h> int main(int argc, char *argv[]) { printf("-28%%3 => %d\n", -28%3); printf("28%%-3 => %d\n", 28%-3); return 0; } -28%3 => -1 28%-3 => 1 And now python
from math import remainder print(-28%3, remainder(-28,3)) print(28%-3, remainder(28,-3)) 2 -1.0 -2 1.0 Why is that? Why does python return 2 for a simple remainder of the division?
%operator in python is modulus. And this is not the same as remainder. - Enikeyschik