Y
Hacker News
new
|
ask
|
show
|
jobs
by
siawyoung
1999 days ago
This makes sure that none of the quantities being calculated will overflow while still returning the same answer.
Where x is min and y is max, the midpoint is:
(x+y)/2 = x+(y-x)/2 x+y = 2x+y-x x+y=x+y