6 ms·
Why not ... x, y = minmax(x, y) return x + (y - x) / 2; ?
by programmer_dude 4y ago
Why not ...
x, y = minmax(x, y)
return x + (y - x) / 2;
?
- lgeorget 4y agoThere's branching involved in the minmax operation, so it'll always be slower than (x|y) - ((x^y)>>1).
- scatters 4y ago(-0x80000000, 0x7fffffff)
- bonzini 4y agomin = x^((y^x)&-(y<x)); return min + ((y^x^min)-min)/2; Still less efficient.
- harerazer 4y agoy - x overflows on y = INT_MAX and x = -1.