--- id: math-posmod name: Math.posmod category: math kind: namespace-method tokens: Math.posmod sig: Math.posmod(a, m) -> int tip: Modulo that is always non-negative. order: 20 ns: Math member: posmod --- Returns a modulo m, but always in the range 0..m-1 — unlike the % operator, which keeps the sign of a (so -1 % 5 is -1, while Math.posmod(-1, 5) is 4). It is what you want for wrapping indices and grid coordinates that can go negative. ```ludic program Demo { handler Step phase Update { let col = Math.posmod(x, grid_width) # never negative } } ```