3 ms·
if a > b { mid = (a-b)/2 That only avoids overflow on unsigned types (where it would be called wraparound) ...
by tromp 4y ago
if a > b {
mid = (a-b)/2
That only avoids overflow on unsigned types (where it would be called wraparound) ...
- eloff 4y agoThe 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.