5.4 Similarities and differences between rem and mod
rem
and mod
are quite similar – they only differ if dividend and divisor have different signs:
With
rem
, the result has the same sign as the dividend (first operand):> 5 rem 4
1
> -5 rem 4
-1
> 5 rem -4
1
> -5 rem -4
-1
With
mod
, the result has the same sign as the divisor (second operand):> 5 mod 4
1
> -5 mod 4
3
> 5 mod -4
-3
> -5 mod -4
-1