1 #ifndef UTIL_RATIONAL_H 2 #define UTIL_RATIONAL_H 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); }
friend Rational operator+(Rational const &a, Rational const &b)
Compute sum of two rationals.
friend Rational operator*(Rational const &a, Rational const &b)
Compute product of rationals.
friend Rational operator/(Rational const &a, Rational const &b)
Compute quotient of two rationals.
Rational & operator*=(Rational const &a)
Multiply this rational by another.
Rational()
Default constructor.
int den() const
Return denominator.
File containing preprocessor macros for error handling.
int gcd(int a, int b)
Compute greatest common divisor (gcd) of two integers.
void serialize(Archive &ar, const unsigned int version)
Serialize to/from an archive.
#define UTIL_THROW(msg)
Macro for throwing an Exception, reporting function, file and line number.
std::istream & operator>>(std::istream &in, Pair< Data > &pair)
Input a Pair from an istream.
Rational & operator-=(Rational const &a)
Subtract another rational from this one.
Utility classes for scientific computation.
friend bool operator==(Rational const &a, Rational const &b)
Equality operators.
static bool hasType
Is the MPI type initialized?
Rational & operator=(Rational const &other)
Copy assignment from another Rational.
Rational & operator+=(Rational const &a)
Add another rational to this one.
#define UTIL_CHECK(condition)
Assertion macro suitable for serial or parallel production code.
static void commitMpiType()
Commit MPI datatype MpiTraits<Rational>::type.
Rational & operator/=(Rational const &a)
Divide this rational by another.
int num() const
Return numerator.
friend Rational operator-(Rational const &a, Rational const &b)
Compute difference of rationals.
A Rational number (a ratio of integers).
friend std::ostream & operator<<(std::ostream &out, Rational const &rational)
Output stream inserter for a Rational.
static MPI::Datatype type
MPI Datatype.
bool operator!=(const PointSymmetry &A, const PointSymmetry &B)
Are two PointSymmetry objects not equivalent?