3 ms·
Meanwhile, C89: https://port70.net/~nsz/c/c89/c89-draft.html#3.3.5 https://port70.net/~nsz/c/c89/c89-draft.html#3.3.5 > When integers are divided and the divi
by __s 5y ago
Meanwhile, C89:
https://port70.net/~nsz/c/c89/c89-draft.html#3.3.5 https://port70.net/~nsz/c/c89/c89-draft.html#3.3.5
> When integers are divided and the division is inexact, if both operands are positive the result of the / operator is the largest integer less than the algebraic quotient and the result of the % operator is positive. If either operand is negative, whether the result of the / operator is the largest integer less than the algebraic quotient or the smallest integer greater than the algebraic quotient is implementation-defined, as is the sign of the result of the % operator. If the quotient a/b is representable, the expression (a/b)*b + a%b shall equal a .
- strenholme 5y agoBetween C89 and C99, the standard was updated to require integer division to truncate towards 0. C99 draft standard: http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1256.pdf http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1256.pdf PDF page 94, physical page 82, “When integers are divided, the result of the / operator is the algebraic quotient with any fractional part discarded.” with a footnote: “This is often called ‘‘truncation toward zero’’” I wish % was a modulo instead of a remainder operation; this bug has bitten me more than once.