- 
                Notifications
    You must be signed in to change notification settings 
- Fork 6.1k
Description
https://github.com/dotnet/docs/blob/master/docs/csharp/language-reference/operators/index.md
This operator is named incorrectly in the documentation. It should be "Remainder" not "Modulus".
In C#, the functionality of the % operator is the Remainder function. The Remainder function returns a value that is the remainder after standard division. For example, 10 % 3 is 1, and this is true for both Remainder and Modulus.
The difference between these two is with negative numbers.
- 
The standard integer division -10 / 3is-3so the Remainder can be found with-10 - (-3)*3which is-1. Remainder ofaandbreturns a value on the range(-b, b)(both exclusive).
- 
However, the Modulus function of -10and3would return2. Modulus satisfies a similar formula but with floored division. Floor division of-10and3is-4instead of-3, and-10 - (-4)*3is2. Modulus ofaandbreturns a value on the range[0, b)(0 inclusive, b exclusive).
- 
C# does not have operators for Modulus or floored division, only Remainder and standard division. The docs should reflect this, so all documentation for %should be renamed to Remainder.
Here's Eric Lippert's thoughts on the issue: https://blogs.msdn.microsoft.com/ericlippert/2011/12/05/whats-the-difference-remainder-vs-modulus/
It's easy to see why this confusion exists, as Remainder and Modulus are equivalent functions for positive numbers. But they are not the same operations. Describing % as Modulus leads to confusion: https://stackoverflow.com/questions/10065080/mod-explanation