I'm working on converting some C# code to Javascript. I have the following code snippet.
float goldenRatioConjugate = 0.618033988749895f;
float currentHue = (float) random.NextDouble();
currentHue += goldenRatioConjugate;
currentHue %= 1.0f;
My question is I don't understand what the last line is doing? I've never seen a modulo operation with a float.
It will set currentHue to the fractional portion of currentHue
For example:
Let suppose
currentHue = 2.5f;
currentHue = (currentHue % 1.0f); /* Output will be 0.5*/
It will first calculate modulus and then assign it to the currentHue which is 0.5 in the above case
currentHue %= 1.0f;
you can write above line as below
currentHue = (currentHue % 1.0f);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With