File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -387,11 +387,23 @@ class polynomial : ordered_euclidean_ring_operators< polynomial<T> >
387387 }
388388
389389 template <class U >
390- BOOST_DEDUCED_TYPENAME enable_if<boost::is_convertible<U,T>, polynomial >::type&
390+ BOOST_DEDUCED_TYPENAME enable_if_c<boost::is_convertible<U,T>::value &&
391+ std::numeric_limits<T>::is_integer, polynomial >::type&
392+ operator %=(const U& value)
393+ {
394+ // In the case that T is integral, this preserves the semantics
395+ // p == r*(p/r) + (p % r), for polynomial<T> p and U r.
396+ modulus (value);
397+ normalize ();
398+ return *this ;
399+ }
400+
401+ template <class U >
402+ BOOST_DEDUCED_TYPENAME enable_if_c<boost::is_convertible<U,T>::value &&
403+ !std::numeric_limits<T>::is_integer, polynomial >::type&
391404 operator %=(const U& /* value*/ )
392405 {
393- // We can always divide by a scalar, so there is no remainder:
394- *this = zero_element (std::multiplies<polynomial>());
406+ m_data.clear ();
395407 return *this ;
396408 }
397409
@@ -526,6 +538,15 @@ class polynomial : ordered_euclidean_ring_operators< polynomial<T> >
526538 return *this ;
527539 }
528540
541+ template <class U >
542+ polynomial& modulus (const U& value)
543+ {
544+ typedef typename std::vector<T>::iterator iter;
545+ for (iter it = m_data.begin (); it != m_data.end (); ++it)
546+ *it -= T (value * T (*it / value));
547+ return *this ;
548+ }
549+
529550 std::vector<T> m_data;
530551};
531552
You can’t perform that action at this time.
0 commit comments