function BigInteger::modInverse
Returns the modular multiplicative inverse of this BigInteger modulo $m.
Throws
DivisionByZeroException If $m is zero.
NegativeNumberException If $m is negative.
MathException If this BigInteger has no multiplicative inverse mod m (that is, this BigInteger is not relatively prime to m).
File
-
vendor/
brick/ math/ src/ BigInteger.php, line 587
Class
- BigInteger
- An arbitrary-size integer.
Namespace
Brick\MathCode
public function modInverse(BigInteger $m) : BigInteger {
if ($m->value === '0') {
throw DivisionByZeroException::modulusMustNotBeZero();
}
if ($m->isNegative()) {
throw new NegativeNumberException('Modulus must not be negative.');
}
if ($m->value === '1') {
return BigInteger::zero();
}
$value = Calculator::get()->modInverse($this->value, $m->value);
if ($value === null) {
throw new MathException('Unable to compute the modInverse for the given modulus.');
}
return new BigInteger($value);
}