示例#1
0
Polynomial&
Polynomial::operator+=(const Monomial& m)
{ 
  if (m.degree() <= this->degree())
    {
      Monomial currentMonomial = mMonomials[m.degree()];

      if (currentMonomial.isZero())   
	{
	  mMonomials[m.degree()] = m;
	}
      else
	{
	  mMonomials[m.degree()] = Monomial(currentMonomial.coefficientReal() + m.coefficientReal(), 
					    currentMonomial.coefficientImag() + m.coefficientImag(),
					    m.degree());
	}
    }
  else
    {
      mMonomials.resize(m.degree() + 1);
      mMonomials[m.degree()] = m;
    }

  /* Possibly deflate the polynomial, if necessary */
  while (mMonomials[degree()].isZero() && degree() > 0)
    {
      mMonomials.resize(degree());
    }

  return *this;
}
示例#2
0
Monomial::Monomial(const Monomial& rhs)
{
  mCoeffR = rhs.coefficientReal();
  mCoeffI = rhs.coefficientImag();
  mDegree = rhs.degree();
}