5 ms·
I think I might be missing the intent of this exercise, but that expression risks overflow (and undefined behaviour) when b is not equal to zero, right?
by MaxBarraclough 6y ago
I think I might be missing the intent of this exercise, but that expression risks overflow (and undefined behaviour) when b is not equal to zero, right?
- arcticbull 6y agoOhhh, I think it also needs to check if (b > 0) in the first arm and (b < 0) in the second arm. -_-
- MaxBarraclough 6y agoYou might be interested in a related challenge: write a function in standard C++ that returns the difference between any pair of int32_t values. This cropped up on StackOverflow. It's tricky enough to trip up the incautious. https://stackoverflow.com/a/61711253/ https://stackoverflow.com/a/61711253/