MoreMathMod Method
Returns the value of n mod m.
Namespace: Meta.NumericsAssembly: Meta.Numerics (in Meta.Numerics.dll) Version: 4.2.0+6d77d64445f7d5d91b12e331399c4362ecb25333
public static long Mod(
long n,
long m
)
Public Shared Function Mod (
n As Long,
m As Long
) As Long
public:
static long long Mod(
long long n,
long long m
)
static member Mod :
n : int64 *
m : int64 -> int64
- n Int64
- The argument.
- m Int64
- The modulus.
Int64The 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.