I am reading revision 4 of the two's-complement proposal (adopted by C++20), and I have some questions.
In the introduction, it says:
Does it really mean "non-commutative", as in a + b
versus b + a
? Or should that read "non-associative"?
It also says:
Hasn't signed-to-unsigned conversion been well-defined in precisely this way since the beginning of time? Should that read "conversion from unsigned to signed"?
Is there anything else in the list of changes that is missing or mis-stated?
Note that it wasn't P0907 that was adopted - it was P1236.
Or should that read "non-associative"?
Yes.
Should that read "conversion from unsigned to signed"?
Yes. If you look at P1236R1, you can see that the rule changed from:
If the destination type is unsigned, the resulting value is the least unsigned integer congruent to the source integer (modulo 2n where n is the number of bits used to represent the unsigned type).
If the destination type is signed, the value is unchanged if it can be represented in the destination type; otherwise, the value is implementation-defined.
to:
Otherwise, the result is the unique value of the destination type that is congruent to the source integer modulo 2N, where N is the range exponent of the destination type.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With