PSCF v1.1
|
A Rational number (a ratio of integers). More...
#include <Rational.h>
Public Member Functions | |
Constructors | |
Rational () | |
Default constructor. More... | |
Rational (int num, int den) | |
Constructor, explicit numerator and denominator. More... | |
Rational (int number) | |
Constructor, construct from integer. More... | |
Rational (Rational const &v) | |
Copy constructor. More... | |
~Rational () | |
Destructor. More... | |
Assignment and Conversion. | |
Rational & | operator= (Rational const &other) |
Copy assignment from another Rational. More... | |
Rational & | operator= (int other) |
Assignment from integer. More... | |
Arithmetic Assignment Operators | |
Rational & | operator+= (Rational const &a) |
Add another rational to this one. More... | |
Rational & | operator+= (int a) |
Add an integer to this rational. More... | |
Rational & | operator-= (Rational const &a) |
Subtract another rational from this one. More... | |
Rational & | operator-= (int) |
Subtract an integer from this rational. More... | |
Rational & | operator*= (Rational const &a) |
Multiply this rational by another. More... | |
Rational & | operator*= (int a) |
Multiply this rational by an integer. More... | |
Rational & | operator/= (Rational const &a) |
Divide this rational by another. More... | |
Rational & | operator/= (int a) |
Divide this rational by an integer. More... | |
Accessors | |
int | num () const |
Return numerator. More... | |
int | den () const |
Return denominator. More... | |
operator double () const | |
Cast (convert) to double precision floating point. More... | |
template<class Archive > | |
void | serialize (Archive &ar, const unsigned int version) |
Serialize to/from an archive. More... | |
static void | commitMpiType () |
Commit MPI datatype MpiTraits<Rational>::type. More... | |
Rational | operator+ (Rational const &a, Rational const &b) |
Compute sum of two rationals. More... | |
Rational | operator+ (Rational const &a, int b) |
Compute sum of rational and integer. More... | |
Rational | operator- (Rational const &a, Rational const &b) |
Compute difference of rationals. More... | |
Rational | operator- (Rational const &a, int b) |
Compute difference of rational and integer. More... | |
Rational | operator- (int b, Rational const &a) |
Compute difference of integer and rational. More... | |
Rational | operator* (Rational const &a, Rational const &b) |
Compute product of rationals. More... | |
Rational | operator* (Rational const &a, int b) |
Compute product of rational and integer. More... | |
Rational | operator/ (Rational const &a, Rational const &b) |
Compute quotient of two rationals. More... | |
Rational | operator/ (Rational const &a, int b) |
Compute quotient Rational divided by integer. More... | |
Rational | operator/ (int b, Rational const &a) |
Compute quotient integer divided by Rational. More... | |
bool | operator== (Rational const &a, Rational const &b) |
Equality operators. More... | |
bool | operator== (Rational const &a, int b) |
Equality operator for a Rational and an integer. More... | |
Rational | operator- (Rational const &a) |
Unary negation of Rational. More... | |
std::ostream & | operator<< (std::ostream &out, Rational const &rational) |
Output stream inserter for a Rational. More... | |
A Rational number (a ratio of integers).
A rational is always stored in a standard reduced form in which the denominator is a positive integer and the numerator and denominator have no common divisors other than unity. All integers, including zero, are stored with a denominator of 1.
Definition at line 33 of file Rational.h.
|
inline |
Default constructor.
Definition at line 271 of file Rational.h.
|
inline |
Constructor, explicit numerator and denominator.
Denominator is reduced to greatest common divisor before return.
num | numerator |
den | denominator |
Definition at line 280 of file Rational.h.
|
inline |
Constructor, construct from integer.
Creates a rational with a denominator == 1.
number | integer number. |
Definition at line 289 of file Rational.h.
|
inline |
|
inline |
Destructor.
Definition at line 75 of file Rational.h.
Copy assignment from another Rational.
other | Rational to assign. |
Definition at line 307 of file Rational.h.
|
inline |
Assignment from integer.
Creates an integer using a denominator == 1.
other | integer to assign. |
Definition at line 318 of file Rational.h.
Add another rational to this one.
Upon return, *this = this + a.
a | increment (input) |
Definition at line 331 of file Rational.h.
|
inline |
Add an integer to this rational.
Upon return, *this = this + a.
a | increment (input) |
Definition at line 343 of file Rational.h.
Subtract another rational from this one.
Upon return, *this = this + a.
a | rational decrement (input) |
Definition at line 354 of file Rational.h.
|
inline |
Subtract an integer from this rational.
Upon return, *this = this + a.
a | integer decrement (input) |
Definition at line 366 of file Rational.h.
Multiply this rational by another.
Upon return, *this = this*a.
a | Rational number to multiply this by (input) |
Definition at line 377 of file Rational.h.
|
inline |
Multiply this rational by an integer.
Upon return, *this = this*a.
a | integer to multiply this by (input) |
Definition at line 389 of file Rational.h.
Divide this rational by another.
Upon return, *this = this*a.
a | rational number to divide this by (input) |
Definition at line 400 of file Rational.h.
References UTIL_THROW.
|
inline |
Divide this rational by an integer.
Upon return, *this = this*a.
a | integer to divide this by (input) |
Definition at line 415 of file Rational.h.
References UTIL_THROW.
|
inline |
Return numerator.
Definition at line 431 of file Rational.h.
|
inline |
Return denominator.
Definition at line 438 of file Rational.h.
|
inline |
Cast (convert) to double precision floating point.
Definition at line 445 of file Rational.h.
|
inline |
Serialize to/from an archive.
ar | archive |
version | archive version id |
Definition at line 454 of file Rational.h.
|
static |
Commit MPI datatype MpiTraits<Rational>::type.
Compute sum of two rationals.
a | 1st argument |
b | 2st argument |
Definition at line 490 of file Rational.h.
Compute sum of rational and integer.
a | Rational argument |
b | integer argument |
Definition at line 505 of file Rational.h.
Compute difference of rationals.
a | 1st argument |
b | 2st argument |
Definition at line 530 of file Rational.h.
Compute difference of rational and integer.
a | Rational argument |
b | integer argument |
Definition at line 545 of file Rational.h.
Compute difference of integer and rational.
b | integer argument |
a | Rational argument |
Definition at line 559 of file Rational.h.
Compute product of rational and integer.
a | Rational argument |
b | integer argument |
Definition at line 588 of file Rational.h.
Compute quotient Rational divided by integer.
a | Rational argument (numerator) |
b | integer argument (denominator) |
Definition at line 628 of file Rational.h.
Compute quotient integer divided by Rational.
b | integer argument (numerator) |
a | Rational argument (denominator) |
Definition at line 644 of file Rational.h.
Equality operators.
Equality operator for two Rational numbers.
Definition at line 674 of file Rational.h.
|
friend |
Equality operator for a Rational and an integer.
a | Rational number |
b | integer number |
Definition at line 684 of file Rational.h.
Unary negation of Rational.
a | Rational number |
Definition at line 661 of file Rational.h.
|
friend |
Output stream inserter for a Rational.
Output elements of a rational to stream, without line breaks.
out | output stream |
rational | Rational to be written to stream |
Definition at line 16 of file Rational.cpp.