Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

    if a > b { 
      mid = (a-b)/2
That only avoids overflow on unsigned types (where it would be called wraparound) ...


The point of the midpoint calculation is to find the mid-index usually (e.g. binary search, quicksort). So a and b would be unsigned. You're right about signed integers though.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: