115 : numerator_(static_cast<T>(r / 100000)), denominator_(static_cast<T>(100000))
121 : numerator_(scale<U>(that.numerator())), denominator_(scale<U>(that.denominator()))
130 if (std::numeric_limits<T>::digits >= std::numeric_limits<U>::digits)
133 return T(value >> (std::numeric_limits<U>::digits - std::numeric_limits<T>::digits));
139 if (denominator_ < value_type())
141 denominator_ = -denominator_;
142 numerator_ = -numerator_;
150 value_type div(gcd(numerator(), denominator()));
151 if (div == value_type())
152 throw zero_denominator(
"zero denominator");
187 numerator_ = numerator() + rhs * denominator();
204 numerator_ = numerator() - rhs * denominator();
250 numerator_ += denominator();
265 numerator_ -= denominator();
389 template<
class T,
class U>
414 bool operator<(rational<T>
const& a,
rational<T> const& b)
421 bool operator<(rational<T>
const& a, T
const& b)
428 bool operator<(T const& a, rational<T>
const& b)
434 template<
class T,
class U>
456 inline bool operator<=(rational<T>
const& a,
rational<T> const& b)
463 inline bool operator<=(rational<T>
const& a, T
const& b)
470 inline bool operator<=(T const& a, rational<T>
const& b)
518 template<
class T,
class Char,
class Traits>
521 typename std::basic_istream<Char, Traits>::sentry sentry(in,
false);
554 template<
class T,
class Char,
class Traits>
555 std::basic_ostream<Char, Traits>& operator<<(std::basic_ostream<Char, Traits>& out,
rational<T> const& rat)
557 typename std::basic_ostream<Char, Traits>::sentry sentry(out);
558 std::ostringstream stream;
currency< T, N > operator+(currency< T, N > a, currency< T, N > b)
bool operator==(currency< T, N > a, currency< T, N > b)
currency< T, N > operator*(currency< T, N > a, T b)
rational & operator=(value_type)
Assignment of an integer.
value_type denominator() const
Return the denominator.
zero_denominator(std::string const &what)
Construct the exception object.
currency< T, N > operator/(currency< T, N > a, T b)
rational & operator-=(rational const &rhs)
Subtraction assignment operator.
value_type numerator() const
Return the numerator.
rational & operator--()
Pre-decrement.
Save and restore I/O stream flags.
rational & operator+=(rational const &rhs)
Addition assignment operator.
bool operator!=(currency< T, N > a, currency< T, N > b)
rational(value_type num=0)
rational & operator*=(rational const &rhs)
Multiplication assignment operator.
rational & operator/=(rational const &rhs)
Division assignment operator.
Represent a rational number (fraction) as a numerator and denominator.
bool operator>=(currency< T, N > a, currency< T, N > b)
T value_type
Convenience typedef for the integral type of the numerator and denominator.
U as() const
Convert the rational number to another type, especially floating-point.
rational & operator++()
Pre-increment.
Exception class if the denominator is ever zero.
bool operator>(currency< T, N > a, currency< T, N > b)
std::basic_istream< Char, Traits > & operator>>(std::basic_istream< Char, Traits > &strm, currency< T, N > &c)
currency< T, N > operator-(currency< T, N > a)
Negate a currency value.