UNPKG

864 BMarkdownView Raw
1<!-- Note: This file is automatically generated from source code comments. Changes made in this file will be overridden. -->
2
3# Function xgcd
4
5Calculate the extended greatest common divisor for two values.
6See https://en.wikipedia.org/wiki/Extended_Euclidean_algorithm.
7
8
9## Syntax
10
11```js
12math.xgcd(a, b)
13```
14
15### Parameters
16
17Parameter | Type | Description
18--------- | ---- | -----------
19`a` | number &#124; BigNumber | An integer number
20`b` | number &#124; BigNumber | An integer number
21
22### Returns
23
24Type | Description
25---- | -----------
26Array | Returns an array containing 3 integers `[div, m, n]` where `div = gcd(a, b)` and `a*m + b*n = div`
27
28
29## Examples
30
31```js
32math.xgcd(8, 12) // returns [4, -1, 1]
33math.gcd(8, 12) // returns 4
34math.xgcd(36163, 21199) // returns [1247, -7, 12]
35```
36
37
38## See also
39
40[gcd](gcd.md),
41[lcm](lcm.md)