Don’t use %. This is a problem that calls for bitmasks:
bool same_parity = (i & 0x1) == (j & 0x1);
This works regardless of the sign of i, since the result of that expression will always be 0 or 1.
Don’t use %. This is a problem that calls for bitmasks:
bool same_parity = (i & 0x1) == (j & 0x1);
This works regardless of the sign of i, since the result of that expression will always be 0 or 1.