UNPKG

913 BMarkdownView Raw
1<!-- Note: This file is automatically generated from source code comments. Changes made in this file will be overridden. -->
2
3# Function gcd
4
5Calculate the greatest common divisor for two or more values or arrays.
6
7For matrices, the function is evaluated element wise.
8
9
10## Syntax
11
12```js
13math.gcd(a, b)
14math.gcd(a, b, c, ...)
15```
16
17### Parameters
18
19Parameter | Type | Description
20--------- | ---- | -----------
21`args` | ... number &#124; BigNumber &#124; Fraction &#124; Array &#124; Matrix | Two or more integer numbers
22
23### Returns
24
25Type | Description
26---- | -----------
27number &#124; BigNumber &#124; Fraction &#124; Array &#124; Matrix | The greatest common divisor
28
29
30## Examples
31
32```js
33math.gcd(8, 12) // returns 4
34math.gcd(-4, 6) // returns 2
35math.gcd(25, 15, -10) // returns 5
36
37math.gcd([8, -4], [12, 6]) // returns [4, 2]
38```
39
40
41## See also
42
43[lcm](lcm.md),
44[xgcd](xgcd.md)