• Create Account

### #ActualBacterius

Posted 18 October 2012 - 07:46 PM

The modulo operator doesn't work as you think it does on floating-point numbers. See this link, down to the floating-point modulo section.

Basically, what it does is it divides the two operands and returns the fractional part (which is always between 0 inclusive and 1 inclusive). In your case, since you are converting that to an int after, you will always get zero no matter what. Using your example, you will get 2.0f % 3.0f = Frac(2.0f / 3.0f) = Frac(0.666..) = 0.666... Truncated down to an integer, you get zero. Not two.

You want to use fmod instead, probably. Or work in sufficiently large integers instead of floating-point numbers.

### #1Bacterius

Posted 18 October 2012 - 07:44 PM

The modulo operator doesn't work as you think it does on floating-point numbers. See this link, down to the floating-point modulo section.

Basically, what it does is it divides the two operands and returns the fractional part (which is always between 0 inclusive and 1 inclusive). In your case, since you are converting that to an int after, you will always get zero no matter what.

You want to use fmod instead, probably.

PARTNERS