Warcraft III resources & community, 2003–2006 · archived

IsIntDivisible

not rated
Submitted by paskovichCalculations0 downloads
Checks if the division gives a whole number or not.
Example:
IsIntDivisible(9,3) == true
IsIntDivisible(9,2) == false
IsIntDivisible(8,2) == true

Can be useful in timers, to call a function every x steps.

Source

//Version 1:
function IsIntDivisible takes integer int, integer divisor returns boolean
    local integer i = int/divisor
    local real    r = I2R(int)/I2R(divisor)
    if i == r then
        return true
    endif
    return false
endfunction

//Version 2:
function IsIntDivisible2 takes integer int, integer divisor returns boolean
    if ModuloInteger(int,divisor)==0 then
	return true
    endif
    return false
endfunction

Comments

4
ugh...

if xxx then return true else return false

can be

return xxx

:?
This is "spam" on the jass section.
The function you have given is as bad as a BJ call.
All it does is return a boolean answer from ModuloInteger().
It is easier just to use "ModuloInteger(int,divisor)==0" in your "if" function and is less cpu draining than using the functions you listed.

It was a good try to liven up the jass section but to bad blizzard included the function already.
lol!! i didn't know that function! :D anyway i wrote an other function that acts the same way. but with the knowladge of the ModuloInteger function it is useles... :D
hmm, do you know the "mod" funktion, it returns the rest of an division (e.g.: 3 mod 2=1, 7 mod 5=2, is a little bit simpler.