Example #1
0
        public (GFPoly Quotient, GFPoly Remainder) Divide(GFPoly other)
        {
            GFPoly quotient            = Zero(GaloisField);
            GFPoly remainder           = this;
            int    denomLeadTerm       = other.GetCoefficient(other.Degree());
            int    inversDenomLeadTerm = GaloisField.Inverse(denomLeadTerm);

            while (remainder.Degree() >= other.Degree() && !remainder.IsZero())
            {
                int    degreeDiff = remainder.Degree() - other.Degree();
                int    scale      = GaloisField.Multiply(remainder.GetCoefficient(remainder.Degree()), inversDenomLeadTerm);
                GFPoly term       = other.MultiplyByMonominal(degreeDiff, scale);
                GFPoly itQuot     = MonominalPoly(GaloisField, degreeDiff, scale);
                quotient  = quotient.AddOrSubtract(itQuot);
                remainder = remainder.AddOrSubtract(term);
            }
            return(quotient, remainder);
        }