2022-03-01 13:04:09 +01:00

55 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-gcd">Function gcd <a href="#function-gcd" title="Permalink">#</a></h1>
Calculate the greatest common divisor for two or more values or arrays.
For matrices, the function is evaluated element wise.
<h2 id="syntax">Syntax <a href="#syntax" title="Permalink">#</a></h2>
```js
math.gcd(a, b)
math.gcd(a, b, c, ...)
```
<h3 id="parameters">Parameters <a href="#parameters" title="Permalink">#</a></h3>
Parameter | Type | Description
--------- | ---- | -----------
`args` | ... number &#124; BigNumber &#124; Fraction &#124; Array &#124; Matrix | Two or more integer numbers
<h3 id="returns">Returns <a href="#returns" title="Permalink">#</a></h3>
Type | Description
---- | -----------
number &#124; BigNumber &#124; Fraction &#124; Array &#124; Matrix | The greatest common divisor
<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.gcd(8, 12) // returns 4
math.gcd(-4, 6) // returns 2
math.gcd(25, 15, -10) // returns 5
math.gcd([8, -4], [12, 6]) // returns [4, 2]
```
<h2 id="see-also">See also <a href="#see-also" title="Permalink">#</a></h2>
[lcm](lcm.html),
[xgcd](xgcd.html)