Hi there,

I have a float called counter that goes from 0 to 31 and then back to 0. I want to be able to specify a number x (0-31) and a threshold th, and check if the number is within th units from the counter.

Sounds easy at first:

if( abs(x - counter) <= th )

But this doesn't work if x is close to 0 and counter is close to 31. I've thought about this for quite a while but can't seem to come up with a solution. Help would be greatly appreciated!