Index: boost/rational.hpp =================================================================== --- boost/rational.hpp (revision 66258) +++ boost/rational.hpp (working copy) @@ -56,6 +56,7 @@ #include // for std::istream and std::ostream #include // for std::noskipws +#include // for floor #include // for std::domain_error #include // for std::string implicit constructor #include // for boost::addable etc @@ -105,23 +106,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 +143,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++(); @@ -215,6 +205,14 @@ return *this; } +// 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()); +} + // Unary plus and minus template inline rational operator+ (const rational& r) @@ -327,6 +325,12 @@ return *this; } +template +rational& rational::operator%= (const rational& r) +{ + return *this -= r * floor(rational_cast(*this / r)); +} + // Mixed-mode operators template inline rational& @@ -356,6 +360,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,14 +594,6 @@ 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).