[petsc-dev] PetscFindInt

Jed Brown jedbrown at mcs.anl.gov
Sat Sep 22 14:47:44 CDT 2012


http://petsc.cs.iit.edu/petsc/petsc-dev/rev/6eccf13462a8

Since when did we start using assert()?

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

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?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-dev/attachments/20120922/84da028c/attachment.html>


More information about the petsc-dev mailing list