What's the difference between “mod” and “remainder”?

后端 未结 5 835

My friend said that there are differences between \"mod\" and \"remainder\".

If so, what are those differences in C and C++? Does \'%\' mean either \"mod\" or \"rem\

5条回答
  •  难免孤独
    2020-11-22 04:52

    Modulus, in modular arithmetic as you're referring, is the value left over or remaining value after arithmetic division. This is commonly known as remainder. % is formally the remainder operator in C / C++. Example:

    7 % 3 = 1  // dividend % divisor = remainder
    

    What's left for discussion is how to treat negative inputs to this % operation. Modern C and C++ produce a signed remainder value for this operation where the sign of the result always matches the dividend input without regard to the sign of the divisor input.

提交回复
热议问题