HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

modulo

11-07-2004, 10:08 PM#1
-={tWiStÄr}=-
i feel like an idiot asking this.. but in the blizzard.j it is like this:
x-(x/y)*y
well i've been racking my brain.. and if you follow order of operations you always get 0.. 10-(10/4)*4 = 10-10 = 0..
so someone come tell me how stupid i am (nicely) then what i'm doing wrong and/or how wc3 order of operations is. cause ive tried everything even other than normal order of operations.
11-07-2004, 10:19 PM#2
Vexorian
Quote:
Originally Posted by -={tWiStÄr}=-
i feel like an idiot asking this.. but in the blizzard.j it is like this:
x-(x/y)*y
well i've been racking my brain.. and if you follow order of operations you always get 0.. 10-(10/4)*4 = 10-10 = 0..
so someone come tell me how stupid i am (nicely) then what i'm doing wrong and/or how wc3 order of operations is. cause ive tried everything even other than normal order of operations.
It is integer division so (13/4)*4 is not 13, it is 12.
11-07-2004, 10:40 PM#3
-={tWiStÄr}=-
wow.. heh.. i hate integer division, it should die. no one likes it. but thanks. i'm guessing in like real math (non-wc3) they use integer division for this also?
11-07-2004, 10:43 PM#4
Vexorian
from blizzard.j

Code:
//===========================================================================
// Calculate the modulus/remainder of (dividend) divided by (divisor).
// Examples:  13.000 mod 2.500 = 0.500.  -6.000 mod 2.500 = 1.500.
//
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

They convert it to an integer, so it is integer division too