Item 49. Parameter Validation
// java.math.BigInteger
/**
* ...
* <p>All methods and constructors in this class throw
* {@code NullPointerException} when passed
* a null object reference for any input parameter.
* ...
*/
public class BigInteger extends Number implements Comparable<BigInteger> {
// ...
/**
* (νμ¬ κ° mod m) κ°μ λ°ννλ€. μ΄ λ©μλλ
* νμ μμ΄ μλ BigIntegerλ₯Ό λ°ννλ€λ μ μμ remainder λ©μλμ λ€λ₯΄λ€.
*
* @param m κ³μ(μμμ¬μΌ νλ€.)
* @return νμ¬ κ° mod m
* @throws ArithmeticException mμ΄ 0λ³΄λ€ μκ±°λ κ°μΌλ©΄ λ°μνλ€.
*/
public BigInteger mod(BigInteger m) {
if (m.signum() <= 0) {
throw new ArithmeticException("κ³μ(m)λ μμμ¬μΌ ν©λλ€. " + m);
}
BigInteger result = this.remainder(m);
return (result.signum >= 0 ? result : result.add(m));
}
// ...
}λ§€κ°λ³μ μ ν¨μ± κ²μ¬μ μ€μμ±
λ§€κ°λ³μ μ ν¨μ± κ²μ¬κ° μλ΅λλ κ²½μ°
Last updated