i'm attempting to build a tiny (or perhaps not so tiny) formula that will contain numbers between a set min and max, but also loop these numbers so they are not clipped if they are outside of the range. so far, this is what i have.
min1 = 10
max1 = 90
val1 = 92
//will make 12, which is what i want since it loops
formula: min(max(min1,min(val1,max1)),mod(val1,max1)+min1)
however, i'd like it to loop the other direction also, so that if val1 is 5, which is -5 outside of min1, it will become 85.
another problem i'm running into is that
max1 % max1 != max1
as i want it to, since the max is part of the range
trying to be clear, here are some examples of desired output based on a range with looping
min1 = 10
max1 = 90
----------------------------------------------
val1 = 30 //within range: stays as 30
val1 = 90 //within range: stays as 90
val1 = -6 //below range: loops to becomes 84
val1 = 98 //above range: loops to becomes 18
i'd like not to resort to using a series of if/else statements, but one would be fine if it's absolutely required. is that even possible?