Skip to content

[numeric.limits.members] The example for is_modulo is not quite correct for small signed integer types #8438

@frederick-vs-ja

Description

@frederick-vs-ja

[numeric.limits.members] currently states:

  1. true if 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 of max() - min() + 1.
  2. [Example 1: is_modulo is 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.

  1. On these platforms, signed char simply satisfies the condition for is_modulo because the value returned always differs from the true value by zero.
  2. Even if we require converting back returned value to singed char, it would always differ from an integer multiple of 256.
  3. Given signed char values are converted due to usual arithmetic conversion first, we may said that signed char values don't actually participate in arithmetic operations (see also LWG554). As a result, is_modulo should be vacuously true for signed 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

No one assigned

    Labels

    lwgIssue must be reviewed by LWG.not-editorialIssue is not deemed editorial; the editorial issue is kept open for tracking.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions