Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. BigInteger.php

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\Math

Code

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);
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal