I have a need of wrapping an int to a specific range, via integer underflow. For example, if the value is greater than x then set it back to its minimum value. I was able to do that part easily enough with a modulo/int overflow (x % max x value). I don’t know, however, how I should go about wrapping it back to its max value when it is lower than its minimum.
Just do it manually. And % works if the range starts with 0, it won’t work if the range is, for instance, [1, 6] or something;
If the range starts with 0, it should be X % (Xmax + 1), shouldn’t it? If the range is [0, 5], 5 % 5 = 0, and 5 % 6 = 5.
But overall, this is what I’d do:
Thanks for the response, I guess that is the easiest way to do it. I am using the modulo for a 0 based index, I just thought there might’ve been a way to calculate it for the opposite direction/underflow.