Expression help: Loop a value within a range
This is slightly difficult to explain for me. I need to loop a value within a range. The easiest comparasion is that "x mod y" loops x within the range 0 to y.
Now, I instead need to loop x within the range y to z, and it needs to work with positive and negative numbers for all three variables. Anyone know a good expression for this?
Re: Expression help: Loop a value within a range
Share the formula for 0 to y? ;)
Re: Expression help: Loop a value within a range
it would be:
(x - y) mod (z - y + 1) + y
except that mod will malfunction when it is negative
see the handy chart on wikipedia for why: http://en.wikipedia.org/wiki/Modulo_operation
so you can just offset it by your biggest possible margin, something like:
(x - y + (z - y + 1) * 500) mod (z - y + 1) + y
Re: Expression help: Loop a value within a range
Looki: I did in the same sentence you quoted ;)
Pixelthief: Awesome, thanks! That'll definitely help me a lot!
Re: Expression help: Loop a value within a range
Oh, sorry, I thought you had a more advanced formula for negative numbers.
Re: Expression help: Loop a value within a range
Ouch, yeah, you're right. Here's the euclidean one: ((x mod y) + y) mod y
In either case, I need this to be a simple expression because I intend to use it a lot, and MMF2 doesn't have customizable expression functions. It's steals so much time to hire an extension developer everytime I need a custom extension (though I'm always very thankful for the ones who helped me), but I guess now is a good time for me dig into C++ for the first time and start out with some "useful maths" extension.
Re: Expression help: Loop a value within a range
Quote:
Originally Posted by Nifflas
It's steals so much time to hire an extension developer everytime I need a custom extension (though I'm always very thankful for the ones who helped me)
I might have something interesting in development for you there. :)