3 ms·
Also, this one: a + (b - a) / 2 has issues that if b is large and a is negative but "large" (in magnitude), then b - a can overflow. I mention that one, si
by deathanatos 10y ago
Also, this one:
a + (b - a) / 2
has issues that if b is large and a is negative but "large" (in magnitude), then b - a can overflow.
I mention that one, since that was how I was taught to do it for binary search, to prevent overflow. (Binary search having the advantage that it can't overflow, b/c a and b represent indexes, and are thus non-negative, so this works there but breaks in the more general case discussed by the paper.)