News for hackers. Stuff that matters.
Re:Beautiful branchless binary search by spc476 on Friday April 28, 2023 @04:44AM (#35738958)
In C, shifting signed integers is undefined behavior.
Re:Beautiful branchless binary search by compiler-guy on Friday April 28, 2023 @01:14PM (#35744227)
Although it can bite you if you don’t know what you are doing, signed-integer shifting is not necessarily undefined behavior. Roughly, for positive signed integers, if the operation doesn’t overflow then the result is defined. For negative signed numbers, right shifts are implementation defined, but almost all modern systems define the result in the expected manner.

https://en.cppreference.com/w/cpp/language/operator_arithmet...

Re:Beautiful branchless binary search by kps on Friday April 28, 2023 @02:00PM (#35744838)
Oh, it's too bad C2x doesn't seem to be following C++20 here, since they're apparently mandating two's complement.