top | item 39289295

(no title)

mbel | 2 years ago

It's not. 0x8000 is the smallest (-32,768) integer that can be represented with 16-bits and two's complement.

discuss

order

pornel|2 years ago

abs() of this value also happens to exceed the maximum positive value. Which means that in C, a simple negation can cause signed integer overflow -(-32768), and therefore UB.

taeric|2 years ago

Yeah, I think it is funny that in a standard binary, it would replace negative zero and makes some sense. In two's complement, it replaces the minimum value.

Fair that sentinel value is sentinel value, I suppose. But it is not like it is not a known and unique number in that encoding.