C++ operator % guarantees
问题 Is it guaranteed that (-x) % m , where x and m are positive in c++ standard (c++0x) is negative and equals to -(x % m) ? I know it's right on all machines I know. 回答1: In addition to Luchian 's answer, this is the corresponding part from the C++11 standard: The binary / operator yields the quotient, and the binary % operator yields the remainder from the division of the first expression by the second. If the second operand of / or % is zero the behavior is undefined. For integral operands the