Hacker News new | past | comments | ask | show | jobs | submit login

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



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.


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.




Join us for AI Startup School this June 16-17 in San Francisco!

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: