gcd.md (965B)
1 <!-- Note: This file is automatically generated from source code comments. Changes made in this file will be overridden. --> 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 ### Throws 31 32 Type | Description 33 ---- | ----------- 34 35 36 ## Examples 37 38 ```js 39 math.gcd(8, 12) // returns 4 40 math.gcd(-4, 6) // returns 2 41 math.gcd(25, 15, -10) // returns 5 42 43 math.gcd([8, -4], [12, 6]) // returns [4, 2] 44 ``` 45 46 47 ## See also 48 49 [lcm](lcm.md), 50 [xgcd](xgcd.md)