* @param m GenPolynomial.
* @return a with with a*this = 1 mod m.
*/
public GenPolynomial<C> modInverse(GenPolynomial<C> m) {
if (this.isZERO()) {
throw new NotInvertibleException("zero is not invertible");
}
GenPolynomial<C>[] hegcd = this.hegcd(m);
GenPolynomial<C> a = hegcd[0];
if (!a.isUnit()) { // gcd != 1
throw new AlgebraicNotInvertibleException("element not invertible, gcd != 1", m, a, m.divide(a));
}
GenPolynomial<C> b = hegcd[1];
if (b.isZERO()) { // when m divides this, e.g. m.isUnit()
throw new NotInvertibleException("element not invertible, divisible by modul");
}
return b;
}