I would like to produce a number that increments in equal steps between between 0.0 and 1.0.
The equal incremental step value will depend on the divisor.
One index "i" is fed into the method and two numbers are produced based on i.
At the moment, this is my working method
void MyMethod(int i, int divisor)
{
i %= divisor;
float v0 = i / (float)divisor;
float v1 = (i + 1) / (float)divisor;
System.Console.WriteLine("v0 = {0}, v1 = {1}", v0, v1);
}
If the divisor is 4 then the results for 0 to 3 inclusive are:
v0 = 0, v1 = 0.25 i = 0
v0 = 0.25, v1 = 0.5 i = 1
v0 = 0.5, v1 = 0.75 i = 2
v0 = 0.75, v1 = 1 i = 3
If the divisor is 4 then the results for 0 to 7 inclusive are:
v0 = 0, v1 = 0.25
v0 = 0.25, v1 = 0.5
v0 = 0.5, v1 = 0.75
v0 = 0.75, v1 = 1
v0 = 0, v1 = 0.25
v0 = 0.25, v1 = 0.5
v0 = 0.5, v1 = 0.75
v0 = 0.75, v1 = 1
This is exactly the behavior I am after but is there a way of getting the same results (i.e. wrapping between 0.0 and 1.0) without using a % operator?
The divisor will always be an integer.