Java BigInteger Mod mod(BigInteger v, BigInteger m)

Here you can find the source of mod(BigInteger v, BigInteger m)

Description

Returns v (mod m).
The value returned lies in range [ 0 ..

License

Open Source License

Parameter

Parameter Description
v a value
m a modulus

Exception

Parameter Description
ArithmeticException when m = 0

Return

v (mod m)

Declaration

public static BigInteger mod(BigInteger v, BigInteger m)
        throws ArithmeticException 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.math.BigInteger;

public class Main {
    /**/*from  ww  w. j  av  a2 s.  c om*/
     * Returns v (mod m).<br>
     * The value returned lies in range [ 0 .. |m| - 1 ].<br>
     * mod( x, m ) = mod( x, -m ).<br>
     * This method differs from {@link java.math.BigInteger#mod} in that it supports negative modulus.<br>
     * If m = 0 then ArithmeticException is thrown.
     * @param v a value
     * @param m a modulus
     * @return v (mod m)
     * @throws ArithmeticException when m = 0
     */
    public static BigInteger mod(BigInteger v, BigInteger m)
            throws ArithmeticException {
        return v.mod(m.abs());
    }
}

Related

  1. mod(BigInteger a, BigInteger b)
  2. mod(BigInteger dividend, BigInteger divisor)