3 ms·
The dev blog from Microsoft in a different comment covers this: "This will be too low if the original addition contained a carry from bit 0 to bit 1, which hap
by Jagerbizzle 4y ago
The dev blog from Microsoft in a different comment covers this:
"This will be too low if the original addition contained a carry from bit 0 to bit 1, which happens if bit 0 is set in both of the terms, so we detect that case and make the necessary adjustment."
return (a / 2) + (b / 2) + (a & b & 1);
- nick4780167 4y agoMaybe a little slower, but way more readable than the ones in the article.
- bonzini 4y agoIt's still wrong for signed integers if a/2 rounds towards zero. You need a>>1 and b>>1.