Re:Binary Search Reconsidered (2018)
by dan-robertson on Friday December 25, 2020 @12:38PM
(#25537802)
In Java (I think that is the implementation language,) longs are 64bit and ints are 32bit, so I think this problem doesn’t come up
[ Parent
| on HN ]
Re:Binary Search Reconsidered (2018)
by PaulKeeble on Friday December 25, 2020 @02:34PM
(#25538488)
It did at one point, I recall Sun had that exact bug at some point back around 1.4, I remember it being fixed. Of course the long conversions alleviate the problem but at a performance cost and its an avoidable cast.
No java doesn't use 64bits at all. It uses unsigned right shift. I mentioned it in another post: "int mid = (low + high) >>> 1;"... And for the older timers (14y ago), there used to be a bug[0] about exactly that.