<HTML>
<HEAD>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<TITLE>
    CWG Issue 1450</TITLE>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<STYLE TYPE="text/css">
  INS { text-decoration:none; font-weight:bold; background-color:#A0FFA0 }
  .INS { text-decoration:none; background-color:#D0FFD0 }
  DEL { text-decoration:line-through; background-color:#FFA0A0 }
  .DEL { text-decoration:line-through; background-color: #FFD0D0 }
  @media (prefers-color-scheme: dark) {
    HTML { background-color:#202020; color:#f0f0f0; }
    A { color:#5bc0ff; }
    A:visited { color:#c6a8ff; }
    A:hover, a:focus { color:#afd7ff; }
    INS { background-color:#033a16; color:#aff5b4; }
    .INS { background-color: #033a16; }
    DEL { background-color:#67060c; color:#ffdcd7; }
    .DEL { background-color:#67060c; }
  }
  SPAN.cmnt { font-family:Times; font-style:italic }
</STYLE>
</HEAD>
<BODY>
<P><EM>This is an unofficial snapshot of the ISO/IEC JTC1 SC22 WG21
  Core Issues List revision 118b.
  See http://www.open-std.org/jtc1/sc22/wg21/ for the official
  list.</EM></P>
<P>2025-09-28</P>
<HR>
<A NAME="1450"></A><H4>1450.
  
<TT>INT_MIN % -1</TT>
</H4>
<B>Section: </B>7.6.5&#160; [<A href="https://wg21.link/expr.mul">expr.mul</A>]
 &#160;&#160;&#160;

 <B>Status: </B>CD3
 &#160;&#160;&#160;

 <B>Submitter: </B>Richard Smith
 &#160;&#160;&#160;

 <B>Date: </B>2012-01-31<BR>


<P>[Moved to DR at the October, 2012 meeting.]</P>



<P>
<A HREF="614.html">Issue 614</A> adopted the corresponding C99
wording for 7.6.5 [<A href="https://wg21.link/expr.mul#4">expr.mul</A>] paragraph 4,</P>

<BLOCKQUOTE>

...if the quotient <TT>a/b</TT> is representable in the type of the result,
<TT>(a/b)*b + a%b</TT> is equal to <TT>a</TT>.

</BLOCKQUOTE>

<P>in an attempt to ensure that <TT>INT_MAX % -1</TT> produces
undefined behavior (because the result is not specified by the
Standard).  However, the new C draft makes the undefined behavior
explicit:</P>

<BLOCKQUOTE>

If the quotient <TT>a/b</TT> is representable, the expression
<TT>(a/b) * b + a%b</TT> shall equal <TT>a</TT>; otherwise, the
behavior of both <TT>a/b</TT> and <TT>a%b</TT> is undefined.

</BLOCKQUOTE>

<P>Should C++ adopt similar wording?</P>

<P><B>Proposed resolution (February, 2012):</B></P>

<P>Change 7.6.5 [<A href="https://wg21.link/expr.mul#4">expr.mul</A>] paragraph 4 as follows:</P>

<BLOCKQUOTE>

...If the second operand of <TT>/</TT> or <TT>%</TT> is zero the
behavior is undefined. For integral operands the <TT>/</TT> operator
yields the algebraic quotient with any fractional part
discarded;<SUP>81</SUP> if the quotient <TT>a/b</TT> is representable
in the type of the result, <TT>(a/b)*b&#160;+&#160;a%b</TT> is equal to
<TT>a</TT><INS>; otherwise, the behavior of both <TT>a/b</TT> and
<TT>a%b</TT> is undefined</INS>.

</BLOCKQUOTE>

<BR><BR>
</BODY>
</HTML>
