2 ms·
Interesting question. Since this is integer division, I think you can do: size_t low_s = low >> 1; size_t high_s = high >> 1; size_t mid = (low_s + h
by mywittyname 6y ago
Interesting question.
Since this is integer division, I think you can do:
size_t low_s = low >> 1;
size_t high_s = high >> 1;
size_t mid = (low_s + high_s)
...With no overflow worries. (expanded for clarity)
That would effectively be distributing the division. So it's equivalent to low / 2 + high / 2.
- saagarjha 6y agoThis gives a different result when both low and high are odd.
- deleted 6y ago[deleted]