Delphi (actually Pascal) has the function Odd(x: integer): boolean which returns true, if the argument is not divisible by 2, false if it is:
if Odd(x) then
WriteLn('Argument is odd.')
else
WriteLn('Argument is even.')
Alternatively one could use the mod operator instead:
if (x mod 2) <> 0 then
WriteLn('Argument is odd.')
else
WriteLn('Argument is even.')
Is there any difference regarding the performance? I'd expect the compiler to generate optimized code for a system function.
I'm particularly interested in an answer regarding Delphi 2007 but if somebody can check other Delphi versions too that would be nice.
Odd
. Sad that there is noEven
to match. – David Heffernan Nov 5 '15 at 15:53