C integer division (source code)

= C integer division
{c}
{title2=$a=bq+r,\quad q=\operatorname{trunc}(a/b)$}

For representable integer quotients with nonzero divisor, <C integer division> discards the fractional part towards zero and defines the remainder by $a=bq+r$. Thus a nonzero remainder has the dividend's sign. For example, $-13=5(-2)+(-3)$, so division by five returns quotient $-2$ and remainder $-3$. This convention differs from division rounded down, which would return quotient $-3$ and nonnegative remainder $2$. Division by zero and an unrepresentable quotient are excluded.<C11 committee draft N1570>[section 6.5.5 paragraphs 5–6]{ref}