by ardel95 · 3y ago · 0 comments
if (a < b)
return a + (b - a) / 2;
else return b + (a - b) / 2;
This method is just more efficient (for places where it matters) as it avoids divisions and branches. But for a vast, vast majority of use-case that tiny efficiency gain doesn’t really matter.min(a,b) + (max(a,b) - min(a,b))>>1