Re:Nearly All Binary Searches and Mergesorts are Broken (2006)
by abecedarius on Thursday July 09, 2015 @06:49PM
(#9861205)
It depends on dialect, but usually variables defaulted to float. I think his code would be OK on arrays that'd fit in 64K (and it'd fail by loss of precision rather than overflow).
FWIW when I coded binary search back in the elder days I checked my C against Bentley's pseudocode but took care about overflow; I didn't judge this difference a bug in the pseudocode, but the sort of consideration necessary in rendering it to C. (Although I was being more careful than usual.) Since this was before the net or open source were part of professional life I didn't get to see other renditions to find out they were wrong.
Re:Nearly All Binary Searches and Mergesorts are Broken (2006)
by im3w1l on Thursday July 09, 2015 @08:22PM
(#9861614)
He uses the cint which forces to int.
Ninjaedit: cint is used for the midpoint, and is then assigned to either the upper or lower limit. After 2 or more iterations, both upper and lower limits can be ints.
Re:Nearly All Binary Searches and Mergesorts are Broken (2006)
by abecedarius on Thursday July 09, 2015 @08:36PM
(#9861674)
After the sum and division.
I only have a basic understanding of basic, but I think the program from programming pearls[0] uses 16 bit integers, and so fails even earlier.
[0] http://www.it.iitb.ac.in/~deepak/deepak/placement/Programmin... page 42(47 of pdf)