On Sat, Sep 22, 2012 at 3:47 PM, Jed Brown <jedbrown at mcs.anl.gov> wrote:
> http://petsc.cs.iit.edu/petsc/petsc-dev/rev/6eccf13462a8 > > Since when did we start using assert()? > Its commented out. > When we discussed this in chat, I specifically asked you to use > > PetscInt imid = imin + (imax - imin)/2; > > but then you went off and wrote this crap > > PetscInt imid = (imin+imax)/2; > > which overflows prematurely. > http://googleresearch.blogspot.com/2006/06/extra-extra-read-all-about-it-nearly.html > Changed to mid = ((unsigned int)low + (unsigned int)high)) >> 1;, which is in the comment above. > Your implementation also does unnecessary arithmetic, but due to possible > overflow, the compiler may not be able to remove it. Why not use the tight > structure I suggested? > http://en.wikipedia.org/wiki/Binary_search Matt -- What most experimenters take for granted before they begin their experiments is infinitely more interesting than any results to which their experiments lead. -- Norbert Wiener -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.mcs.anl.gov/pipermail/petsc-dev/attachments/20120922/e5ed6bea/attachment.html>
