News for hackers. Stuff that matters.
Re:Binary search with confidence by charcircuit on Monday March 07, 2022 @09:42AM (#30588359)
It's more comparable to:

  int add(int x, int y) { return (2*x + 2*y) / 2; }
If ints are 32 bit you would expect to be able to add 1 to 2^20, but that causes an overflow with this implementation. (low + high) / 2 is arguably worse because you turn the algorithm from working on any array into one that only works on arrays that are small enough not to cause the overflow.

There are no comments on this comment yet.