Numbers.gcd()

Syntax

function gcd(...values: number[]): number

Returns the greatest common divisor of two or more integers.

Parameters
values Rest

Two or more non-zero integers from which the greatest common divisor should be calculated. If less than two integers are specified, some numbers are floating point numbers, or some numbers are 0, this function will return 0.

Example

import { Numbers } from 'potence';

Numbers.gcd(8, 12);          // -> 4
Numbers.gcd(505, 202, 303);  // -> 101

Remarks

The greatest common divisor is the greatest positive integer that divides all the integers to which it applies without a remainder.

This function uses the Euclidean algorithm to obtain its result.

Compare Numbers.lcm().