15#include <util/mpi/MpiTraits.h>
192 operator double ()
const;
202 template <
class Archive>
203 void serialize(Archive & ar,
const unsigned int version);
333 num_ = num_*a.den_ + a.num_*den_;
356 num_ = num_*a.den_ - a.num_*den_;
403 UTIL_THROW(
"Attempt to divide by zero Rational");
418 UTIL_THROW(
"Attempt to divide Rational by zero integer");
445 Rational::operator double ()
const
446 {
return double(num_)/double(den_); }
453 template <
class Archive>
464 void Rational::reduce ()
474 int c =
gcd(num_, den_);
492 int num = a.num_*b.den_ + b.num_*a.den_;
493 int den = a.den_*b.den_;
507 int num = a.num_ + b*a.den_;
532 int num = a.num_*b.den_ - b.num_*a.den_;
533 int den = a.den_*b.den_;
547 int num = a.num_ - b*a.den_;
561 int num = b*a.den_ - a.num_;
575 int num = a.num_*b.num_;
576 int den = a.den_*b.den_;
589 {
return Rational(b*a.num_, a.den_); }
613 UTIL_THROW(
"Attempt to divide by zero Rational");
615 int num = a.num_*b.den_;
616 int den = a.den_*b.num_;
631 UTIL_THROW(
"Attempt to divide Rational by zero integer");
647 UTIL_THROW(
"Attempt to divide integer by zero Rational");
662 {
return Rational(-a.num_, a.den_); }
675 {
return ((a.num_ == b.num_) && (a.den_ == b.den_)); }
685 {
return ((a.num_ == b) && (a.den_ == 1)); }
707 {
return !(a == b); }
717 {
return !(a == b); }
727 {
return !(a == b); }
739 std::ostream&
operator << (std::ostream& out, Rational
const & rational);
751 std::istream&
operator >> (std::istream& in, Rational & rational);
static MPI::Datatype type
MPI Datatype.
static bool hasType
Is the MPI type initialized?
A Rational number (a ratio of integers).
int num() const
Return numerator.
friend std::ostream & operator<<(std::ostream &out, Rational const &rational)
Output stream inserter for a Rational.
Rational & operator/=(Rational const &a)
Divide this rational by another.
Rational()
Default constructor.
Rational & operator*=(Rational const &a)
Multiply this rational by another.
friend bool operator==(Rational const &a, Rational const &b)
Equality operators.
friend Rational operator*(Rational const &a, Rational const &b)
Compute product of rationals.
Rational & operator+=(Rational const &a)
Add another rational to this one.
static void commitMpiType()
Commit MPI datatype MpiTraits<Rational>::type.
Rational & operator=(Rational const &other)
Copy assignment from another Rational.
Rational & operator-=(Rational const &a)
Subtract another rational from this one.
int den() const
Return denominator.
friend Rational operator-(Rational const &a, Rational const &b)
Compute difference of rationals.
friend Rational operator+(Rational const &a, Rational const &b)
Compute sum of two rationals.
void serialize(Archive &ar, const unsigned int version)
Serialize to/from an archive.
friend Rational operator/(Rational const &a, Rational const &b)
Compute quotient of two rationals.
File containing preprocessor macros for error handling.
#define UTIL_CHECK(condition)
Assertion macro suitable for serial or parallel production code.
#define UTIL_THROW(msg)
Macro for throwing an Exception, reporting function, file and line number.
int gcd(int a, int b)
Compute greatest common divisor (gcd) of two integers.
Utility classes for scientific computation.
Rational operator*(Rational const &a, Rational const &b)
Compute product of rationals.
Rational operator+(Rational const &a, Rational const &b)
Compute sum of two rationals.
Rational operator/(Rational const &a, Rational const &b)
Compute quotient of two rationals.
bool operator==(Polynomial< T > const &a, Polynomial< T > const &b)
Equality operator for polynomials.
Polynomial< T > operator-(Polynomial< T > const &a)
Unary negation of polynomial.
std::istream & operator>>(std::istream &in, Pair< Data > &pair)
Input a Pair from an istream.
std::ostream & operator<<(std::ostream &out, const Pair< Data > &pair)
Output a Pair to an ostream, without line breaks.
bool operator!=(Polynomial< T > const &a, Polynomial< T > const &b)
Inequality operator for polynomials.