> a mod b = ((a % b) + b) % b
The first remainder bounds it to -b < x < b. Then adding b goes to 0 < x < 2b. Then the second remainder gets th desired 0 <= x < b.
This will not work for b > max_int / 2 (solution in that case is much mkre language dependent)
> a mod b = ((a % b) + b) % b
The first remainder bounds it to -b < x < b. Then adding b goes to 0 < x < 2b. Then the second remainder gets th desired 0 <= x < b.
This will not work for b > max_int / 2 (solution in that case is much mkre language dependent)