1 |
|
2 |
|
3 | # Function gcd
|
4 |
|
5 | Calculate the greatest common divisor for two or more values or arrays.
|
6 |
|
7 | For matrices, the function is evaluated element wise.
|
8 |
|
9 |
|
10 | ## Syntax
|
11 |
|
12 | ```js
|
13 | math.gcd(a, b)
|
14 | math.gcd(a, b, c, ...)
|
15 | ```
|
16 |
|
17 | ### Parameters
|
18 |
|
19 | Parameter | Type | Description
|
20 | --------- | ---- | -----------
|
21 | `args` | ... number | BigNumber | Fraction | Array | Matrix | Two or more integer numbers
|
22 |
|
23 | ### Returns
|
24 |
|
25 | Type | Description
|
26 | ---- | -----------
|
27 | number | BigNumber | Fraction | Array | Matrix | The greatest common divisor
|
28 |
|
29 |
|
30 | ## Examples
|
31 |
|
32 | ```js
|
33 | math.gcd(8, 12) // returns 4
|
34 | math.gcd(-4, 6) // returns 2
|
35 | math.gcd(25, 15, -10) // returns 5
|
36 |
|
37 | math.gcd([8, -4], [12, 6]) // returns [4, 2]
|
38 | ```
|
39 |
|
40 |
|
41 | ## See also
|
42 |
|
43 | [lcm](lcm.md),
|
44 | [xgcd](xgcd.md)
|