Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Questions about C++20 two's-complement proposal R4

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:

  • Status-quo Signed integer arithmetic remains non-commutative in general (though some implementations may guarantee that it is).

Does it really mean "non-commutative", as in a + b versus b + a? Or should that read "non-associative"?

It also says:

  • Change Conversion from signed to unsigned is always well-defined: the result is the unique value of the destination type that is congruent to the source integer modulo 2^N.

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?

like image 772
Nemo Avatar asked Sep 20 '19 16:09

Nemo


1 Answers

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.

like image 75
Barry Avatar answered Oct 22 '22 00:10

Barry