Hacker News
new
|
past
|
comments
|
ask
|
show
|
jobs
|
submit
login
tromp
on Dec 7, 2022
|
parent
|
context
|
favorite
| on:
Fast midpoint between two integers without overflo...
if a > b { mid = (a-b)/2
That only avoids overflow on unsigned types (where it would be called wraparound) ...
slashdev
on Dec 7, 2022
[–]
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: