Algorithm Request: Comparison against a range that wraps


Author Message
jirsoft

Guru

Joined: 18/09/2020
Location: Czech Republic
Posts: 533
Posted: 08:22am 25 Jun 2021      

I will prepare both values with MOD to  proper range 0-MAX, so you will have for example 2 values 0-359 for angle or 0:00-11:59 for 12-hour clock time.
Then if smallest difference
min(max(a,b)-min(a,b), WRAP+min(a,b)-max(a,b))
where WRAP is 360 for angle and 12:00 for time...