3 ms·
The difference is that (a) that bit in OCaml has a purpose, while disregarding 0x80..00 hasn't; and (b) I assume that it was in OCaml from the beginning, so it
by rob74 3y ago
The difference is that (a) that bit in OCaml has a purpose, while disregarding 0x80..00 hasn't; and (b) I assume that it was in OCaml from the beginning, so it wouldn't break existing software in probably very interesting ways (hence the suggestion that this should be done only "in the privacy of their own bedrooms with new types", i.e. not for already-used types)...
- JKCalhoun 3y agoYes, correct me if I'm wrong, but I thought the point was that 0x8000 is like negative zero and so of no utility, redundant. So let's make it useful.
- mbel 3y agoIt's not. 0x8000 is the smallest (-32,768) integer that can be represented with 16-bits and two's complement.
- taeric 3y agoYeah, 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.
- pornel 3y agoabs() 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.
- gridspy 3y agoA couple of things that are special about 2s compliment - There are no redundant numbers like -0 - Adding two integers together in this format works with negative and positive numbers with no special case. -1 is actually 0xFF or 0xFFFF etc. So 0xFF + 0x01 (-1 + 1) "overflows" to 0.