3 ms·
Other comments point out that can overflow for some values. However if you're doing mid-point in something like binary search where you already know y >= x AND
by jlokier 4y ago
Other comments point out that can overflow for some values.
However if you're doing mid-point in something like binary search where you already know y >= x AND x >= 0, then x + (y - x) / 2 is indeed a fine choice. It's a good one to remember.