예제 #1
0
	Polynom Polynom::operator*(const Polynom & poly) const
	{
		Polynom res;
		for (int i = 0; i <= Power() + poly.Power(); ++i) {
			for (int j = 0; j <= i; ++j) {
				res.SetCoef(i, res[i] + (*this)[j] * poly[i - j]);
			}
		}
		return res;
	}
예제 #2
0
	bool Polynom::operator==(const Polynom & poly) const
	{
		int minPow = (std::min)(Power(), poly.Power());
		int maxPow = (std::max)(Power(), poly.Power());
		const Polynom & maxPoly = ((*this).Power() == maxPow) ? *this : poly;

		for (int i = 0; i <= minPow; ++i) {
			if (!AlmostZero((*this)[i] - poly[i]))
				return false;
		}
		for (int i = minPow + 1; i <= maxPow; ++i) {
			if (!AlmostZero(maxPoly[i]))
				return false;
		}

		return true;
	}