Most programming languages ββuse a symmetric module, which differs from the mathematical one for negative values.
The mathematical module can be calculated using symmetric modulo as follows:
a mod b = ((a % b) + b) % b
mod math modulo
% symmetric modulo
source share