function BigInteger::modPow
Returns this number raised into power with modulo.
This operation only works on positive numbers.
Parameters
BigNumber|int|float|string $exp The exponent. Must be positive or zero.:
BigNumber|int|float|string $mod The modulus. Must be strictly positive.:
Throws
NegativeNumberException If any of the operands is negative.
DivisionByZeroException If the modulus is zero.
File
-
vendor/
brick/ math/ src/ BigInteger.php, line 621
Class
- BigInteger
- An arbitrary-size integer.
Namespace
Brick\MathCode
public function modPow(BigNumber|int|float|string $exp, BigNumber|int|float|string $mod) : BigInteger {
$exp = BigInteger::of($exp);
$mod = BigInteger::of($mod);
if ($this->isNegative() || $exp->isNegative() || $mod->isNegative()) {
throw new NegativeNumberException('The operands cannot be negative.');
}
if ($mod->isZero()) {
throw DivisionByZeroException::modulusMustNotBeZero();
}
$result = Calculator::get()->modPow($this->value, $exp->value, $mod->value);
return new BigInteger($result);
}