示例#1
0
 inline void Polynomial<T, Structure>::divide(const Polynomial<T, Structure>& divisor, Polynomial<T, Structure>& quotient, Polynomial<T, Structure>& remainder) const
 {
   if (deg() < divisor.deg()) {
     remainder = *this;
     quotient = zero();
     return;
   }
   size_type divisor_deg = divisor.deg();
   size_type new_deg = deg() - divisor_deg;
   remainder = *this;
   if (deg() < divisor_deg) {
     quotient = one();
     return;
   }
   coefficient_list quotient_coefficients (new_deg + 1);
   const T divisor_first_digit = divisor.m_coefficients[divisor_deg];
   for (size_type i = new_deg + 1; i > 0;) {
     --i;
     quotient_coefficients[i] = remainder.m_coefficients[i + divisor_deg] / divisor_first_digit;
     Polynomial<T, Structure> factor (m_structure, quotient_coefficients[i], i);
     Polynomial<T, Structure> back_calculated = factor * divisor;
     remainder.subtract(back_calculated);
   }
   remainder.remove_zeros();
   quotient = Polynomial<T, Structure>(m_structure, quotient_coefficients);
 }
void Polynomial::operator/=(const Polynomial& p)
{
    Polynomial Q = *this;
    while(Q.get_degree()>=p.get_degree())
    {
        Q-=p*p(p.get_degree())*Q(Q.get_degree());
        Q.remove_zeros();
    }
    *this = Q;
}