# Fix the Euclidean operator to work with negative steps #73

Merged
merged 1 commit into from Mar 14, 2016

## Conversation

Projects
None yet
2 participants
Collaborator

### samdoshi commented Mar 14, 2016

 The `ER` operator wasn't working correctly with a negative step value. Negative steps can come about in normal use when you're trying to do an offset, e.g. ``````ER fill length SUB step rotation `````` Anyway, turns out `%` in C is a remainder, rather than modulo, e.g: ```#include int main() { for (int step=-10; step<=10; step++) { int length = 4; int remainder = step % length; int modulo = remainder < 0 ? remainder + length : remainder; printf("step: %3i remainder: %2i modulo: %i\n", step, remainder, modulo); } }``` gives: ``````step: -10 remainder: -2 modulo: 2 step: -9 remainder: -1 modulo: 3 step: -8 remainder: 0 modulo: 0 step: -7 remainder: -3 modulo: 1 step: -6 remainder: -2 modulo: 2 step: -5 remainder: -1 modulo: 3 step: -4 remainder: 0 modulo: 0 step: -3 remainder: -3 modulo: 1 step: -2 remainder: -2 modulo: 2 step: -1 remainder: -1 modulo: 3 step: 0 remainder: 0 modulo: 0 step: 1 remainder: 1 modulo: 1 step: 2 remainder: 2 modulo: 2 step: 3 remainder: 3 modulo: 3 step: 4 remainder: 0 modulo: 0 step: 5 remainder: 1 modulo: 1 step: 6 remainder: 2 modulo: 2 step: 7 remainder: 3 modulo: 3 step: 8 remainder: 0 modulo: 0 step: 9 remainder: 1 modulo: 1 step: 10 remainder: 2 modulo: 2 ``````
``` fix euclidean operator to work with negative steps ```
`the remainder operator, a % b, is bounded -b < a < b, we need 0 <= a < b`
``` 88c949f ```

### tehn added a commit that referenced this pull request Mar 14, 2016

``` Merge pull request #73 from samdoshi/er-fix ```
`Fix the Euclidean operator to work with negative steps`
``` 3e4a063 ```