Re:Finding the average of two unsigned integers without over...
by nonsequitur on Tuesday February 08, 2022 @07:02AM
(#30257450)
This doesn't work because you're not left-shifting (doubling) the carry. But when adding the shifted carry to (x ^ y) we're back to potentially overflowing the highest bits.
The solution is to add the highest and the lower bits separately:
Note this only improves performance for larger container integers.
[ Parent
| on HN ]