Skip to main content

posmod

Function posmod 

pub fn posmod(x: i64, y: i64) -> i64
Expand description

Returns the integer modulus of x divided by y that wraps equally in positive and negative.

print("#(i)  (i % 3)   (posmod(i, 3))")
for i in range(-3, 4):
	print("%2d       %2d  | %2d" % [i, i % 3, posmod(i, 3)])

Prints:

(i)  (i % 3)   (posmod(i, 3))
-3        0  |  0
-2       -2  |  1
-1       -1  |  2
 0        0  |  0
 1        1  |  1
 2        2  |  2
 3        0  |  0