News for hackers. Stuff that matters.
Re:Fast midpoint between two integers without overflow by baobabKoodaa on Wednesday December 07, 2022 @06:58PM (#33902162)
min + (max - min) / 2

Edit: never mind, this can overflow too

Re:Fast midpoint between two integers without overflow by stephencanon on Wednesday December 07, 2022 @08:37PM (#33902975)
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.