Content deleted Content added
|
|
isOdd = i % 2 ;isOdd is non-zero if i is odd
isEven = i % 2 ! 1 ;isEven is non-zero if i is even</lang>
=={{header|Prolog}}==
Prolog does not provide special even or odd predicates as one can simply write "0 is N mod 2"
to test whether the integer N is even. To illustrate, here is a predicate that can
be used both to test whether an integer is even and to generate the non-negative even numbers:
<lang prolog>
even(N) :-
(between(0, inf, N); integer(N) ),
0 is N mod 2.
</lang>
===Least Significant Bit===
If N is a positive integer, then lsb(N) is the offset of its least significant bit, so we could write:
<lang prolog>
odd(N) :- N = 0 -> false; 0 is lsb(abs(N)).
</lang>
=={{header|Python}}==
|