File tree Expand file tree Collapse file tree 2 files changed +10
-6
lines changed
Expand file tree Collapse file tree 2 files changed +10
-6
lines changed Original file line number Diff line number Diff line change @@ -112,15 +112,13 @@ Array<Monomial<T>> Polynomial<T>::Mult(const Array<Monomial<T>> &p_one,
112112
113113template <class T > Polynomial<T> Polynomial<T>::DivideByPolynomial(const Polynomial &den) const
114114{
115- const Polynomial zero (m_space, static_cast <T>(0 ));
116-
117- if (den == zero) {
115+ if (den.IsZero ()) {
118116 throw ZeroDivideException ();
119117 }
120118
121119 // assumes exact divisibility!
122- Polynomial<T> result (m_space);
123- if (* this == zero ) {
120+ Polynomial result (m_space);
121+ if (IsZero () ) {
124122 return result;
125123 }
126124
@@ -134,7 +132,7 @@ template <class T> Polynomial<T> Polynomial<T>::DivideByPolynomial(const Polynom
134132 }
135133
136134 Polynomial remainder (*this );
137- while (remainder != zero ) {
135+ while (!remainder. IsZero () ) {
138136 const int deg_rem = remainder.DegreeOfVar (last);
139137 const int deg_den = den.DegreeOfVar (last);
140138
Original file line number Diff line number Diff line change @@ -34,6 +34,7 @@ class VariableSpace {
3434 int number{0 };
3535 };
3636
37+ VariableSpace () = delete ;
3738 explicit VariableSpace (size_t nvars)
3839 {
3940 for (size_t i = 1 ; i <= nvars; i++) {
@@ -370,6 +371,11 @@ template <class T> class Polynomial {
370371 });
371372 }
372373 [[nodiscard]] const Array<Monomial<T>> &GetTerms () const noexcept { return m_terms; }
374+ bool IsZero () const noexcept { return m_terms.empty (); }
375+ bool IsConstant () const noexcept
376+ {
377+ return m_terms.size () == 1 && m_terms.front ().TotalDegree () == 0 ;
378+ }
373379
374380 Polynomial LeadingCoefficient (int varnumber) const ;
375381 T NumLeadCoeff () const
You can’t perform that action at this time.
0 commit comments