Page 1 of 1

Thoughts on floor() function use

Posted: 21 Jan 2012 23:09
by dsorlien
I've been thinking about how I have been using the floor() function. To scale an x=0 to 1 value to some integer range 0 to n, I'd use the expression:
floor(x * n)

So for instance, to get an integer value 0 to 10:
output = floor(x * 10)
when x is between 0.000 and 0.099, the output is 0
when x is between 0.100 and 0.199, the output is 1
etc.
when x is between 0.900 and 0.999, the output is 9
when x is exactly 1.000, the output is 10

Here's the problem: The rotation range of the knob is NOT divided equally using the above scheme.

Perhaps a better way to generate the integer value 0 to n would be something like this:
output = floor(x * (n + 0.999))

This would give a roughly equal range for each possible output value.