-
Notifications
You must be signed in to change notification settings - Fork 803
Open
Labels
lwgIssue must be reviewed by LWG.Issue must be reviewed by LWG.not-editorialIssue is not deemed editorial; the editorial issue is kept open for tracking.Issue is not deemed editorial; the editorial issue is kept open for tracking.
Description
[numeric.limits.members] currently states:
trueif the type is modulo.182) A type is modulo if, for any operation involving+,-, or*on values of that type whose result would fall outside the range [min(),max()], the value returned differs from the true value by an integer multiple ofmax() - min() + 1.- [Example 1:
is_modulois false for signed integer types ([basic.fundamental]) unless an implementation, as an extension to this document, defines signed integer overflow to wrap. — end example]
On most modern platforms, signed char is 8-bit and int is 32-bit. For any operation involving +, -, or * on two signed char values, the operands are converted to int first, and the behavior is always well-defined and the result (of type int) is always mathematically correct.
There seems to be different interpretations for this case.
- On these platforms,
signed charsimply satisfies the condition foris_modulobecause the value returned always differs from the true value by zero. - Even if we require converting back returned value to
singed char, it would always differ from an integer multiple of 256. - Given
signed charvalues are converted due to usual arithmetic conversion first, we may said thatsigned charvalues don't actually participate in arithmetic operations (see also LWG554). As a result,is_moduloshould be vacuouslytrueforsigned char(and other non-promoted integer types).
So IIUC std::numeric_limits<signed char>::is_modulo should be true on these platforms and the example is incorrect.
Also, it's not clear why std::numeric_limits<bool>::is_modulo is false. This doesn't seem correct unless the returned value is required to be converted back to bool.
Metadata
Metadata
Assignees
Labels
lwgIssue must be reviewed by LWG.Issue must be reviewed by LWG.not-editorialIssue is not deemed editorial; the editorial issue is kept open for tracking.Issue is not deemed editorial; the editorial issue is kept open for tracking.