Isn't your implementation UB? You cast after the addition? So you're casting the result, after the signed overflow (UB) would have already happened, no?
you're correct. Thanks for flagging this! I've accidentally used one of the earlier C++ versions I've used for experimentation and forgot to update it to final
Isn't your implementation UB? You cast after the addition? So you're casting the result, after the signed overflow (UB) would have already happened, no?
you're correct. Thanks for flagging this! I've accidentally used one of the earlier C++ versions I've used for experimentation and forgot to update it to final
```
constexpr int midpoint(int l, int r) {
return static_cast<unsigned int>(l) + static_cast<unsigned int>(r) >> 1;
}
```
https://godbolt.org/z/G7ecY4MWY