What is the difference between remainder and modulus?
Remainder and modulus differ in the cases in which the numerator’s and quotient’s signs differ. The remainder is based on rounding down (towards zero; truncate): [trunc(5,3)==1, rem(5,3)==2] 5==1*3+2, -5==-1*3+-2, 5==-1*-3+2, -5==1*-3+-2; the remainder gets the numerator’s sign. Modulus is based on rounding floor (towards negative): 5==1*3+2, -5==-2*3+1, 5==-2*-3+-1, -5==1*-3+-2; the remainder gets the quotient’s sign.