cplusplus/CWG

[basic.fundamental] p2 `modulo` is ambigous in defining result

Opened this issue · 2 comments

Full name of submitter (unless configured in github; will be published with the issue): Jim X

[basic.fundamental] p2 says:

arithmetic for the unsigned type is performed modulo 2N.

Consider this example:

int main(){
   auto r = 2u - 4u;
}

Modulo Wiki says
图片

The rule defines the result as -2 mod 4294967296, which in turn, is determined by what modulo means here. modulo has different definitions on mathematics and computer science, which determines whether the remainder is a positive number or a negative.

Suggested Resolution

arithmetic for the unsigned type is a unique value of that type that is congruent to the result of the arithmetic modulo 2N

Per search results of "is performed modulo", I find that when one says "is performed modulo" (exactly these 3 English words), the operation is always arithmetic modulo and there doesn't seem any counterexample. Also, I guess the sentence should be moved somewhere in [expr] as it's entirely about evaluation of some expressions.

Concerns here can be handled editorially IMO (if improvements are desired).

arithmetic for the unsigned type is a unique value of that type that is congruent to the result of the arithmetic modulo 2N

The suggestion seemingly says that "some kind of arithmetic is some value", which seems semantically ill-formed to me. Presumably "produces" should be used instead of "is".

agree that this is editorial