>Thanks, this could have been mentioned in docs so it would not be a surprise when working with negative numbers.
I'd want it mentioned in the docs if it returned either 1 or -1. That mod(-13,4)=3 is mathematically correct, i.e. that's the expected value, no surprises there. It's just that most of us tend to forget that particular neck of the mathematical woods :).