2 ms·
> delta = abs(x - y); > The argument is that unsigned is dangerous here because if y > x then you get underflow. The problem with this argument is it’s not val
by ajuc 5y ago
> delta = abs(x - y);
> The argument is that unsigned is dangerous here because if y > x then you get underflow. The problem with this argument is it’s not valid because the code itself is simply incorrect regardless of the signedness of x and y. There are values for both x and y which will lead to signed integer underflow. So like before, in languages like C and C++, you just unconditionally invoked undefined behavior since signed integer underflow is undefined.
Yeah because x=1, y=2 is just as likely an input as x=MIN_SIGNED_INT, y=1.