odd and even numbers

Paul D. DeRocco pderocco at ix.netcom.com
Mon Aug 5 16:30:46 EDT 2013


> From: dunbarx at aol.com
> 
> Just ask yourself this"
> 
> answer testNumber mod 2
> 
> If you get a "1", testnumber is odd, if a "0", even.

Careful, x mod 2 will be -1 for a negative odd number. Better to test for
zero (even) or nonzero (odd).

By the way bitwise AND normally works for negative or positive numbers on a
two's complement machine (which is probably every machine that LiveCode ever
has or ever will run on. In C, one can test for an odd integer with x & 1.
Yet bitAnd doesn't work on negative numbers. It is documented that way, but
I think this is an unnecessary and unexpected limitation.

-- 

Ciao,               Paul D. DeRocco
Paul                mailto:pderocco at ix.netcom.com 





More information about the use-livecode mailing list