r/programming • u/SilasX • May 09 '15
"Real programmers can do these problems easily"; author posts invalid solution to #4
https://blog.svpino.com/2015/05/08/solution-to-problem-4
3.1k
Upvotes
r/programming • u/SilasX • May 09 '15
3
u/[deleted] May 09 '15
The binary search algorithm from the Programming Pearls book was famous for that. It bisected by evaluating
(lower + upper) / 2, which (as 32 bit machines approached their limits) has an unnecessary overflow issue. Using a signed integer type makes the problem hit even sooner. Though it takes a very large array of very small items to hit the limit anyway, and switching to 64 bit integers avoids the bug anyway - at least for now.