Advertisement
Miseryk

C++ Branchless Abs

Mar 21st, 2023
680
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.09 KB | Source Code | 0 0
  1. int abs(int x)
  2. {
  3.     int mask = x >> (sizeof(int) * 8 - 1);
  4.     return (x + mask) ^ mask;
  5. }
Tags: C++ branchless
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement