Why do such operations:
std::cout << (-7 % 3) << std::endl;
std::cout << (7 % -3) << std::endl;
give different results?
-1
1
Why do such operations:
std::cout << (-7 % 3) << std::endl;
std::cout << (7 % -3) << std::endl;
give different results?
-1
1
in c++ default:
in python:
in c++ to python:
From ISO14882:2011(e) 5.6-4:
The rest is basic math:
Note that
from ISO14882:2003(e) is no longer present in ISO14882:2011(e)
The sign in such cases (i.e when one or both operands are negative) is implementation-defined. The spec says in §5.6/4 (C++03),
That is all the language has to say, as far as C++03 is concerned.