I'd like to access elements in an array in a circular manner. Normally a modulo suffices but in Julia arrays start at 1. At the moment I'm basically converting the indices to a 0-based index and back. But this doesn't work for negative indices.
A = 1:5
for i in -6:6
println(i, " -> ", ((i - 1) % length(A)) + 1)
end
Output
-6 -> -1 # wrong
-5 -> 0 # wrong
-4 -> 1 # wrong
-3 -> -3 # wrong
-2 -> -2 # wrong
-1 -> -1 # wrong
0 -> 0 # wrong
1 -> 1
2 -> 2
3 -> 3
4 -> 4
5 -> 5
6 -> 1