src/NeinMath/IntegerFunctions.cs
/// <summary>
/// Performs modulus inversion on an Integer.
/// </summary>
/// <param name="value">The Integer to inverse.</param>
/// <param name="modulus">The Integer by which to divide.</param>
/// <returns>The result of inversing the Integer; if any.</returns>
Performs modulus inversion on an Integer.
Performs modulus inversion on an Integer .
public static Integer ModInv(this Integer value, Integer modulus)
        {
            if (modulus < 1)
                throw new ArgumentOutOfRangeException(nameof(modulus));
            if (Abs(value) >= modulus)
                value = value % modulus;
            if (value < 0)
            {
                value = value + modulus;
                var result = Lehmer.Inv(modulus, value);
                if (result != 0)
                    result = result - modulus;
                return result;
            }
            return Lehmer.Inv(modulus, value);
        }
public static Integer ModInv ( this Integer value , Integer modulus ) { if ( modulus < 1 ) throw new ArgumentOutOfRangeException ( nameof ( modulus ) ) ; if ( Abs ( value ) >= modulus ) value = value % modulus ; if ( value < 0 ) { value = value + modulus ; var result = Lehmer . Inv ( modulus , value ) ; if ( result != 0 ) result = result - modulus ; return result ; } return Lehmer . Inv ( modulus , value ) ; }
Performs modulus inversion on an Integer.
Performs modulus inversion on an Integer .
The result of inversing the Integer; if any.
The result of inversing the Integer ; if any .
Integer
this
modulus
Integer
The Integer by which to divide.
The Integer by which to divide .
value
The Integer to inverse.
The Integer to inverse .