C
Craig
Will -x == ~x + 1 always be true if x is an unsigned integer type?
This certainly won't always hold if x is signed. The reason I come to
this conclusion is that unsigned numbers must wrap, and there is no
special logic for handling negative numbers. This would then cause
unsigned numbers to behave as 2-s complement numbers, and thus
guarantee -x == ~x + 1.
This certainly won't always hold if x is signed. The reason I come to
this conclusion is that unsigned numbers must wrap, and there is no
special logic for handling negative numbers. This would then cause
unsigned numbers to behave as 2-s complement numbers, and thus
guarantee -x == ~x + 1.