Quoted from JohnCampbell
mod(I+p,p) = mod(I,p)
Not always!
Counterexample: mod(-2, 3) = -2, but mod(-2+3, 3) = 1
It is quite easy to make such slips if one or both the arguments to the mod() function, or its sister function modulo(), are negative. Modular arithmetic can be counter-intuitive if one is not used to it. For example, (a + b) mod c need not equal (a mod c) + (b mod c); consider a=1, b=1, c=2.
The rule is: Given two numbers (real or integer) A and P, of the same type and kind, find the integer K = INT(A/P) in the case of mod() and K = FLOOR(A/P) in the case of modulo(). The value of the function is A - K*P, and '/' has its mathematical meaning, not 'integer division'.
The functions can be used in a number of situations where one has to find the nearest from a set of discrete values. I use the mod() function frequently in an iterative algorithm to monitor the progress: IF (mod(ITER, PRNTINTVL) == 0) WRITE(,)...