Little Arithmetics

The solution here was pretty simple: if the number is outside the range, use some arithmetic to get it inside the range. – Inessential

Brent Simmons’ blog is a treasure trove of little development tips and tricks.