mirror of
https://github.com/josdejong/mathjs.git
synced 2026-01-18 14:59:29 +00:00
975 B
975 B
Function lcm
Calculate the least common multiple for two or more values or arrays.
lcm is defined as:
lcm(a, b) = abs(a * b) / gcd(a, b)
For matrices, the function is evaluated element wise.
Syntax
math.lcm(a, b)
math.lcm(a, b, c, ...)
Parameters
| Parameter | Type | Description |
|---|---|---|
args |
... Number | BigNumber | Boolean | Array | Matrix | null | Two or more integer numbers |
Returns
| Type | Description |
|---|---|
| Number | BigNumber | Array | Matrix | The least common multiple |
Examples
math.lcm(4, 6); // returns 12
math.lcm(6, 21); // returns 42
math.lcm(6, 21, 5); // returns 210
math.lcm([4, 6], [6, 21]); // returns [12, 42]