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

Breadcrumb

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

function Calculator::modInverse

Returns the modular multiplicative inverse of $x modulo $m.

If $x has no multiplicative inverse mod m, this method must return null.

This method can be overridden by the concrete implementation if the underlying library has built-in support.

Parameters

string $m The modulus; must not be negative or zero.:

1 method overrides Calculator::modInverse()
GmpCalculator::modInverse in vendor/brick/math/src/Internal/Calculator/GmpCalculator.php
Returns the modular multiplicative inverse of $x modulo $m.

File

vendor/brick/math/src/Internal/Calculator.php, line 233

Class

Calculator
Performs basic operations on arbitrary size integers.

Namespace

Brick\Math\Internal

Code

public function modInverse(string $x, string $m) : ?string {
    if ($m === '1') {
        return '0';
    }
    $modVal = $x;
    if ($x[0] === '-' || $this->cmp($this->abs($x), $m) >= 0) {
        $modVal = $this->mod($x, $m);
    }
    [
        $g,
        $x,
    ] = $this->gcdExtended($modVal, $m);
    if ($g !== '1') {
        return null;
    }
    return $this->mod($this->add($this->mod($x, $m), $m), $m);
}

API Navigation

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