As such say you put together something like this:
The fix method works just fine at correcting the zero relative index value if it goes over, but what if I give it a negative number?
This is not the way I would expect modulo to work for me most of the time when given a negative number. The spinner example reflects what I expect from a modulo operation most of the time where -8 would whip back around and land on 2. It’s not wrong in the sense that 5 - 3 = 2, but with certain values it gives numbers like negative zero so I end up with 5 - -0 = 5 where I want the value to be 0.
Now that I am using a custom cut modulo method that does work as expected I now of course get the results that I want. I first fount this little gem of a method called Mathematical modulo in the source code of angles.js, which is a great little library by the way with all kinds of helpful methods that have to do with working with, you guessed it, angles. It sure is work checking out if you get a chance.
So often I use the custom modulo in situations in which module is called for. Often I might be using modulo in expressions with values that might go into the negative number range, and thus using a custom modulo method to get the results that I want is often called for.
The angles.js library that contained the mathematical modulo method that prompted me to write this post appears to no longer be maintained. That is not always such a bad thing assuming that the methods still work okay, and I would say that is more or less the case. Still I have taken the time to make my own angles.js module that I might come back to now and then when it comes to working out all kinds of things that have to do with angles. As such the mathematical modulo method should be a part of that kind of module, so the post that I wrote on my angles module might be worth checking out when it comes to applications of the mathematical modulo method.