First of all, there is a mod operator, and it's called
mod.
function is_even(num)
even = (num mod 2 = 0)
endfunction even
And if there weren't one, you seem to be on the right track and could just do something like this:
function is_even(num)
even = 0
if (num/2.0) - (num/2) = 0.0 then even = 1
endfunction even
In that case (num/2.0) is a proper float division (resulting in 3.5 for num = 7 for instance) and (num/2) is an integer division (7/2 = 3). Alternatively you could write it like this:
function is_even(num)
v# = num/2.0
rest# = v#-floor(v#) //or int(v#) but that could lead to problems with negative numbers
if rest# = 0.0 then even = 1 else even = 0
endfunction even
If you stick to integers as possible input, you could also use bit masks instead of mod (might be faster).
function is_odd(num)
odd = num && 1 //Setting all bits to 0 except the very last one
endfunction odd
rem Or to invert it
function is_even(num)
even = ((num && 1) ~~ 1)
endfunction even
But I'd rather stick to the first solution.
Edit: Actually this would be somewhat easier than the int division method above:
function is_odd(num)
odd = num - (num/2)*2
endfunction odd
function is_even(num)
even = 1 - is_odd(num)
endfunction even
But again, this might only work for positive integers.