- Joined
- Oct 12, 2008
- Messages
- 1,570
Hello Hivers.
I have seen this function in use, and i cannot understand how this can ever work!?
Now i have been thinking, and with the basic math rules, i can only get an answer around 0. Multiplying comes before addition and substraction.
That will make
Now when we substract (almost) dividend from dividend, we get 0. Right?
Or does Jass not follow the basic math rules?
I am confused, can you explain?
-Yixx,,-
I have seen this function in use, and i cannot understand how this can ever work!?
JASS:
function ModuloReal takes real dividend, real divisor returns real
local real modulus = dividend - I2R(R2I(dividend / divisor)) * divisor
// If the dividend was negative, the above modulus calculation will
// be negative, but within (-divisor..0). We can add (divisor) to
// shift this result into the desired range of (0..divisor).
if (modulus < 0) then
set modulus = modulus + divisor
endif
return modulus
endfunction
That will make
dividend/divisor * divisor
the same as 'dividend'. Or almost, because the they use I2R(R2I()).Now when we substract (almost) dividend from dividend, we get 0. Right?
Or does Jass not follow the basic math rules?
I am confused, can you explain?
-Yixx,,-