Index: boost/rational.hpp =================================================================== --- boost/rational.hpp (revision 73242) +++ boost/rational.hpp (working copy) @@ -105,23 +105,10 @@ template class rational : - less_than_comparable < rational, - equality_comparable < rational, - less_than_comparable2 < rational, IntType, - equality_comparable2 < rational, IntType, - addable < rational, - subtractable < rational, - multipliable < rational, - dividable < rational, - addable2 < rational, IntType, - subtractable2 < rational, IntType, - subtractable2_left < rational, IntType, - multipliable2 < rational, IntType, - dividable2 < rational, IntType, - dividable2_left < rational, IntType, - incrementable < rational, - decrementable < rational - > > > > > > > > > > > > > > > > + ordered_euclidean_ring_operators < rational, + ordered_euclidean_ring_operators2 < rational, IntType, + unit_steppable < rational + > > > { // Class-wide pre-conditions BOOST_STATIC_ASSERT( ::std::numeric_limits::is_specialized ); @@ -155,11 +142,13 @@ rational& operator-= (const rational& r); rational& operator*= (const rational& r); rational& operator/= (const rational& r); + rational& operator%= (const rational& r); rational& operator+= (param_type i); rational& operator-= (param_type i); rational& operator*= (param_type i); rational& operator/= (param_type i); + rational& operator%= (param_type i); // Increment and decrement const rational& operator++(); @@ -205,6 +194,14 @@ void normalize(); }; +// Type conversion +template +inline T rational_cast( + const rational& src BOOST_APPEND_EXPLICIT_TEMPLATE_TYPE(T)) +{ + return static_cast(src.numerator())/static_cast(src.denominator()); +} + // Assign in place template inline rational& rational::assign(param_type n, param_type d) @@ -327,6 +324,12 @@ return *this; } +template +rational& rational::operator%= (const rational& r) +{ + return *this -= r * rational_cast(*this / r); +} + // Mixed-mode operators template inline rational& @@ -356,6 +359,13 @@ return operator/= (rational(i)); } +template +inline rational& +rational::operator%= (param_type i) +{ + return operator%= (rational(i)); +} + // Increment and decrement template inline const rational& rational::operator++() @@ -583,24 +593,13 @@ return os; } -// Type conversion -template -inline T rational_cast( - const rational& src BOOST_APPEND_EXPLICIT_TEMPLATE_TYPE(T)) -{ - return static_cast(src.numerator())/static_cast(src.denominator()); -} - // Do not use any abs() defined on IntType - it isn't worth it, given the // difficulties involved (Koenig lookup required, there may not *be* an abs() // defined, etc etc). template inline rational abs(const rational& r) { - if (r.numerator() >= IntType(0)) - return r; - - return rational(-r.numerator(), r.denominator()); + return r.numerator() >= IntType(0)? r: -r; } } // namespace boost