[numeric.limits.members] The example for `is_modulo` is not quite correct for small signed integer types
Nobody has claimed this yet.
- Dominant language
- TeX
- Stars
- 221
- Forks
- 813
- Avg merge
- 16h 4m
- Merged PRs (30d)
- 36
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.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the [numeric.limits.members] wording and Example 1, then read the issue's discussion of integral promotions and LWG554. Compare the treatment of signed small integer types and bool against the definition of is_modulo. Done means the standard wording and example clearly resolve both cases.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- documentation
- Issue type
- Documentation
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100