function _xgcd(a, b) {
    // source: https://en.wikipedia.org/wiki/Extended_Euclidean_algorithm
    var t; // used to swap two variables

    var q; // quotient

    var r; // remainder

    var x = 0;
    var lastx = 1;
    var y = 1;
    var lasty = 0;

    if (!isInteger(a) || !isInteger(b)) {
      throw new Error('Parameters in function xgcd must be integer numbers');
    }

    while (b) {
      q = Math.floor(a / b);
      r = a - q * b;
      t = x;
      x = lastx - q * x;
      lastx = t;
      t = y;
      y = lasty - q * y;
      lasty = t;
      a = b;
      b = r;
    }

    var res;

    if (a < 0) {
      res = [-a, -lastx, -lasty];
    } else {
      res = [a, a ? lastx : 0, lasty];
    }

    return config.matrix === 'Array' ? res : matrix(res);
  }
Calculate xgcd for two numbers
@param {number} a
@param {number} b
@return {number} result
@private