docs: function inverseMod_(x, n) {
    var k=1+2*Math.max(x.length, n.length);
  
    if (!(x[0]&1)  && !(n[0]&1)) {  //if both inputs are even, then inverse doesn't exist
      copyInt_(x, 0);
      return 0;
    }
  
    if (eg_u.length!=k) {
      eg_u=new Array(k);
      eg_v=new Array(k);
      eg_A=new Array(k);
      eg_B=new Array(k);
      eg_C=new Array(k);
      eg_D=new Array(k);
    }
  
    copy_(eg_u, x);
    copy_(eg_v, n);
    copyInt_(eg_A, 1);
    copyInt_(eg_B, 0);
    copyInt_(eg_C, 0);
    copyInt_(eg_D, 1);
    for (;;) {
      while (!(eg_u[0]&1)) {  //while eg_u is even
        halve_(eg_u);
        if (!(eg_A[0]&1) && !(eg_B[0]&1)) { //if eg_A==eg_B==0 mod 2
          halve_(eg_A);
          halve_(eg_B);
        } else {
          add_(eg_A, n);  halve_(eg_A);
          sub_(eg_B, x);  halve_(eg_B);
        }
      }
  
      while (!(eg_v[0]&1)) {  //while eg_v is even
        halve_(eg_v);
        if (!(eg_C[0]&1) && !(eg_D[0]&1)) { //if eg_C==eg_D==0 mod 2
          halve_(eg_C);
          halve_(eg_D);
        } else {
          add_(eg_C, n);  halve_(eg_C);
          sub_(eg_D, x);  halve_(eg_D);
        }
      }
  
      if (!greater(eg_v, eg_u)) { //eg_v <= eg_u
        sub_(eg_u, eg_v);
        sub_(eg_A, eg_C);
        sub_(eg_B, eg_D);
      } else {                   //eg_v > eg_u
        sub_(eg_v, eg_u);
        sub_(eg_C, eg_A);
        sub_(eg_D, eg_B);
      }
  
      if (equalsInt(eg_u, 0)) {
        while (negative(eg_C)) //make sure answer is nonnegative
          add_(eg_C, n);
        copy_(x, eg_C);
  
        if (!equalsInt(eg_v, 1)) { //if GCD_(x,n)!=1, then there is no inverse
          copyInt_(x, 0);
          return 0;
        }
        return 1;
      }
    }
  }