News for hackers. Stuff that matters.
Re:Subtraction is not comparison by ambrop7 on Friday December 26, 2014 @04:16AM (#8798513)
Just do (x>y)-(x<y). It's actually pretty fast: http://stackoverflow.com/questions/10996418/efficient-intege...

Disclaimer: not actually my original invention.

Re:Subtraction is not comparison by pkhuong on Friday December 26, 2014 @09:38AM (#8798916)
That's a good one for integers and if you don't intend the comparator to be inlined. For inlined comparison, I prefer if (x == y) return 0; return (x < y) ? -1 : 1;. The control flow is more transparent and C compilers are usually able to perform the if/if conversion necessary to get the single comparison you'd expect in hand-rolled sorts or searches.