Most commanly the modulo operator %
is used to test against an even or odd Number.
Now my question is, is there any Problem testing against an odd number using a bitwise AND, as it feels much more natural testing whether the rightmost bit is 1
or 0
than doing a modulo check against 2
And as the 32 bit conversion does not change the rightmost bit.
Both
(1 + Math.pow(2,52)) & 1 //1
and
(1 + Math.pow(2,52)) % 2 //1
yield the same result.
Is there a reason to prefer the modulo operator over the bitwise?
Edit:
This question only accounts for values that fall in the range of 64bit precision
as only even numbers can be represented precise above 2^53 and therefore both operands fail (9007199254740993 % 2 //0)