3 ms·
>This bug can manifest itself for arrays whose length (in elements) is 2^30 or greater (roughly a billion elements). This was inconceivable back in the '80s, wh
by im3w1l 11y ago
>This bug can manifest itself for arrays whose length (in elements) is 2^30 or greater (roughly a billion elements). This was inconceivable back in the '80s, when Programming Pearls was written, but it is common these days at Google and other places
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/Programming_pearls.pdf http://www.it.iitb.ac.in/~deepak/deepak/placement/Programmin... page 42(47 of pdf)
- abecedarius 11y agoIt 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.
- im3w1l 11y agoHe 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.
- abecedarius 11y agoAfter the sum and division.