Hacker News new | ask | show | jobs
by pklausler 3479 days ago
Oh, come on, you don't need a branch to do a conditional subtraction. Reify the condition to 0/1 and use multiplication, or use AND with a two's complement of the condition.
3 comments

OK, my bit twiddling knowledge is weak, my google skills are weaker still, and now I'm curious: what does "AND with a two's complement of the condition" mean, exactly?
x -= N & -(x >= N);
Ohh, nice, I get it now. Thanks a lot!
Thanks! This AND trick is great. Actually makes me want to go back to assembly-level programming.
Good point!