how do I limit a range of numbers to between 0 and 1?
scitunes
Member, Sous Chef Posts: 4,047
I have the accelerometer value + a constant (comes from my calibration method) and I want to limit the range of the sum of these two numbers to no less than 0 and no more than 1. So -.2 returns a value of 0 and 1.3 returns a value of 1.
Any ideas? floor? ceil?
Thanks!
Any ideas? floor? ceil?
Thanks!
Comments
...and what about multipliers...
floor((abs(your-value*10))/10)
min(upper limit, max(lower limit, original number));
So in your case it would look like this (with limits of 0 and 1):
game.constrainedValue = min(1,max(0,(accelerometer value + constant)))
Hope this helps!
Joe
Although, I think the min and max numbers are reversed in the newer formula.
@photics: The min() and max() are not reversed...
Think of it this way:
`MIN` = getMin
`MAX` = getMax