2022-07-25 10:14:12 +02:00

52 lines
1.4 KiB
Markdown

---
layout: default
---
<!-- Note: This file is automatically generated from source code comments. Changes made in this file will be overridden. -->
<h1 id="function-invmod">Function invmod <a href="#function-invmod" title="Permalink">#</a></h1>
Calculate the (modular) multiplicative inverse of a modulo b. Solution to the equation `ax ≣ 1 (mod b)`
See https://en.wikipedia.org/wiki/Modular_multiplicative_inverse.
<h2 id="syntax">Syntax <a href="#syntax" title="Permalink">#</a></h2>
```js
math.invmod(a, b)
```
<h3 id="parameters">Parameters <a href="#parameters" title="Permalink">#</a></h3>
Parameter | Type | Description
--------- | ---- | -----------
`a` | number &#124; BigNumber | An integer number
`b` | number &#124; BigNumber | An integer number
<h3 id="returns">Returns <a href="#returns" title="Permalink">#</a></h3>
Type | Description
---- | -----------
number &#124; BigNumber | Returns an integer number where `invmod(a,b)*a ≣ 1 (mod b)`
<h3 id="throws">Throws <a href="#throws" title="Permalink">#</a></h3>
Type | Description
---- | -----------
<h2 id="examples">Examples <a href="#examples" title="Permalink">#</a></h2>
```js
math.invmod(8, 12) // returns NaN
math.invmod(7, 13) // returns 2
math.invmod(15151, 15122) // returns 10429
```
<h2 id="see-also">See also <a href="#see-also" title="Permalink">#</a></h2>
[gcd](gcd.html),
[xgcd](xgcd.html)