I found the following behavior surprising:
int a = -2;
int b = 5;
uint c = 5;
std::cout << a%b << '\n';
std::cout << a%c << '\n';
Output:
-2
4
When comparisons are involved, mixing signed and unsigned is problematic - is there a hidden comparison in the operator %
, or is there something else taking place here?