Re:Python, unlike C, has the mod operator always return a po...
by fanf2 on Wednesday December 29, 2021 @08:08PM
(#29732276)
The language in the reference manual at the end of the book (p. 188) is much more specific. It says:
The binary operator / indicates division. When positive integers are divided, truncation is toward 0, but the form of truncation is machine-dependent if either operand is negative. On all machines covered by this manual, the remainder has the same sign as the dividend. It is always true that (a/b)*b + a%b is equal to a (if b is not 0). The binary % operator yields the remainder from division of the first operand by the second.
Re:Python, unlike C, has the mod operator always return a po...
by jounker on Thursday December 30, 2021 @02:20AM
(#29734497)
Interesting. If the equality must hold, then this means that a/b has different values on different architectures depending on whether a%b is positive or negative.
The binary operator / indicates division. When positive integers are divided, truncation is toward 0, but the form of truncation is machine-dependent if either operand is negative. On all machines covered by this manual, the remainder has the same sign as the dividend. It is always true that (a/b)*b + a%b is equal to a (if b is not 0). The binary % operator yields the remainder from division of the first operand by the second.