Hacker News
new
|
past
|
comments
|
ask
|
show
|
jobs
|
submit
login
baobabKoodaa
on Dec 7, 2022
|
parent
|
context
|
favorite
| on:
Fast midpoint between two integers without overflo...
min + (max - min) / 2
Edit: never mind, this can overflow too
stephencanon
on Dec 8, 2022
[–]
Fortunately the cases where this might overflow (a and b have opposite sign) are precisely the cases where the naive (a+b)/2 is guaranteed to work. So put them together to get a suboptimal but perfectly fine solution.
Guidelines
|
FAQ
|
Lists
|
API
|
Security
|
Legal
|
Apply to YC
|
Contact
Search:
Edit: never mind, this can overflow too