I'm looking for a way to implement a custom underflow. My code expects a range of 0-52 and if it goes outside this range it should overflow/underflow.
I've implemented a working simple solution for the overflow by doing value % 53
so if I'll give it a value over 52 it will still give me a value inside the range. For example, 53 = 0, 54 = 1, 55 = 2
.
The underflow should work in the opposite way to the overflow, for example -1 = 52, -2 = 51, -3 = 50
.
How can I implement that?