4 ms·
TIL these two lines (to get an integer absolute value without branching) are _patented_: int const mask = v >> sizeof(int) * CHAR_BIT - 1; r = (v ^ mask) -
by almog 6y ago
TIL these two lines (to get an integer absolute value without branching) are _patented_:
int const mask = v >> sizeof(int) * CHAR_BIT - 1;
r = (v ^ mask) - mask;