3 ms·
No? If x is 3, then (x * 2) / 2 is also equal to 3 (as per the GP) but (x & ~1 * 2) / 2 is equal to 0. (If you meant ((x & ~1) * 2) / 2, then that is equal to
by caf 8y ago
No?
If x is 3, then (x * 2) / 2 is also equal to 3 (as per the GP) but (x & ~1 * 2) / 2 is equal to 0.
(If you meant ((x & ~1) * 2) / 2, then that is equal to 2).
- cornholio 8y agoYou are of course correct. Not only have I mistook precedence, but I confused the lower bit with the upper one where overflow occurs. So the compiler optimizable fix is something like: ((x & INT_MAX) * 2) / 2 = x