2014-05-17 12:21:31 +02:00

885 B

Function xgcd

Calculate the extended greatest common divisor for two values. See http://en.wikipedia.org/wiki/Extended_Euclidean_algorithm.

Syntax

math.xgcd(a, b)

Parameters

Parameter Type Description
a Number | Boolean An integer number
b Number | Boolean An integer number

Returns

Type Description
Array Returns an array containing 3 integers [div, m, n] where div = gcd(a, b) and a*m + b*n = div

Examples

var math = mathjs();

math.xgcd(8, 12);             // returns [4, -1, 1]
math.gcd(8, 12);              // returns 4
math.xgcd(36163, 21199);      // returns [1247, -7, 12]

See also

gcd, lcm