Skip to main content

Mojo function

circular_add

circular_add[n: Int](x: Int, y: Int) -> Int

Addition modulo n, assuming 0 <= x < n and 0 <= y < n.

Equivalent to (x + y) % n. When n is a power of 2, uses unsigned modulo which compiles to a single and instruction. Otherwise uses a conditional subtract to avoid expensive integer division on GPU.

Returns:

Int

Was this page helpful?