Click or drag to resize
MoreMathMod Method
Returns the value of n mod m.

Namespace:  Meta.Numerics
Assembly:  Meta.Numerics (in Meta.Numerics.dll) Version: (
public static long Mod(
	long n,
	long m


Type: SystemInt64
The argument.
Type: SystemInt64
The modulus.

Return Value

Type: Int64
The value of n mod m.
The modulus operator in .NET languages (n % m in C#, n Mod m in VB) returns a negative remainder for negative n. This is not consistent with the mathematical conventions of modular arithmetic, which require that 0 ≤ n mod m < m. For example, in C# -7 % 4 returns -3 (which is simply the negative of 7 % 4), while mathematically -7 mod 4 = 1, as can seen by extending the repeating 0, 1, 2, 3 pattern to negative integers. In cases where it is important to obtain results consistent mathematical conventions, you should call this method, which fixes the .NET result.
See Also