On Sat, Sep 22, 2012 at 3:47 PM, Jed Brown <span dir="ltr"><<a href="mailto:jedbrown@mcs.anl.gov" target="_blank">jedbrown@mcs.anl.gov</a>></span> wrote:<br><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<a href="http://petsc.cs.iit.edu/petsc/petsc-dev/rev/6eccf13462a8" target="_blank">http://petsc.cs.iit.edu/petsc/petsc-dev/rev/6eccf13462a8</a><div><br></div><div>Since when did we start using assert()?</div></blockquote>
<div><br></div><div>Its commented out.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div>When we discussed this in chat, I specifically asked you to use</div>

<div><br></div><div>PetscInt imid = imin + (imax - imin)/2;</div><div><br></div><div>but then you went off and wrote this crap</div><div><br></div><div>PetscInt imid = (imin+imax)/2;</div><div><br></div><div>which overflows prematurely. <a href="http://googleresearch.blogspot.com/2006/06/extra-extra-read-all-about-it-nearly.html" target="_blank">http://googleresearch.blogspot.com/2006/06/extra-extra-read-all-about-it-nearly.html</a></div>
</blockquote><div><br></div><div>Changed to <span style="background-color:rgb(255,255,255);color:rgb(51,51,51);font-size:14px;line-height:19px;text-align:justify">mid = ((unsigned int)low + (unsigned int)high)) >> 1;, </span>which is in the comment above.</div>
<div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div>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?</div>

</blockquote></div><br><a href="http://en.wikipedia.org/wiki/Binary_search">http://en.wikipedia.org/wiki/Binary_search</a><div><br></div><div>   Matt<br clear="all"><div><br></div>-- <br>What most experimenters take for granted before they begin their experiments is infinitely more interesting than any results to which their experiments lead.<br>
-- Norbert Wiener<br>
</div>