PSCF v1.3
|
A Rational number (a ratio of integers). More...
#include <Rational.h>
Public Member Functions | |
Constructors | |
Rational () | |
Default constructor. | |
Rational (int num, int den) | |
Constructor, explicit numerator and denominator. | |
Rational (int number) | |
Constructor, construct from integer. | |
Rational (Rational const &v) | |
Copy constructor. | |
~Rational () | |
Destructor. | |
Assignment and Conversion. | |
Rational & | operator= (Rational const &other) |
Copy assignment from another Rational. | |
Rational & | operator= (int other) |
Assignment from integer. | |
Arithmetic Assignment Operators | |
Rational & | operator+= (Rational const &a) |
Add another rational to this one. | |
Rational & | operator+= (int a) |
Add an integer to this rational. | |
Rational & | operator-= (Rational const &a) |
Subtract another rational from this one. | |
Rational & | operator-= (int) |
Subtract an integer from this rational. | |
Rational & | operator*= (Rational const &a) |
Multiply this rational by another. | |
Rational & | operator*= (int a) |
Multiply this rational by an integer. | |
Rational & | operator/= (Rational const &a) |
Divide this rational by another. | |
Rational & | operator/= (int a) |
Divide this rational by an integer. |
Accessors | |
int | num () const |
Return numerator. | |
int | den () const |
Return denominator. | |
operator double () const | |
Cast (convert) to double precision floating point. | |
template<class Archive> | |
void | serialize (Archive &ar, const unsigned int version) |
Serialize to/from an archive. | |
Rational | operator+ (Rational const &a, Rational const &b) |
Compute sum of two rationals. | |
Rational | operator+ (Rational const &a, int b) |
Compute sum of rational and integer. | |
Rational | operator- (Rational const &a, Rational const &b) |
Compute difference of rationals. | |
Rational | operator- (Rational const &a, int b) |
Compute difference of rational and integer. | |
Rational | operator- (int b, Rational const &a) |
Compute difference of integer and rational. | |
Rational | operator* (Rational const &a, Rational const &b) |
Compute product of rationals. | |
Rational | operator* (Rational const &a, int b) |
Compute product of rational and integer. | |
Rational | operator/ (Rational const &a, Rational const &b) |
Compute quotient of two rationals. | |
Rational | operator/ (Rational const &a, int b) |
Compute quotient Rational divided by integer. | |
Rational | operator/ (int b, Rational const &a) |
Compute quotient integer divided by Rational. | |
bool | operator== (Rational const &a, Rational const &b) |
Equality operators. | |
bool | operator== (Rational const &a, int b) |
Equality operator for a Rational and an integer. | |
Rational | operator- (Rational const &a) |
Unary negation of Rational. | |
std::ostream & | operator<< (std::ostream &out, Rational const &rational) |
Output stream inserter for a Rational. |
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.
Referenced by operator*, operator*, operator*=(), operator*=(), operator+, operator+, operator+=(), operator+=(), operator-, operator-, operator-, operator-, operator-=(), operator-=(), operator/, operator/, operator/, operator/=(), operator/=(), operator<<, operator=(), operator=(), operator==, operator==, and Rational().
|
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 |
Copy constructor.
v | Rational to be copied |
Definition at line 298 of file Rational.h.
References Rational().
|
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.
References Rational().
|
inline |
Assignment from integer.
Creates an integer using a denominator == 1.
other | integer to assign. |
Definition at line 318 of file Rational.h.
References Rational().
Add another rational to this one.
Upon return, *this = this + a.
a | increment (input) |
Definition at line 331 of file Rational.h.
References Rational().
|
inline |
Add an integer to this rational.
Upon return, *this = this + a.
a | increment (input) |
Definition at line 343 of file Rational.h.
References Rational().
Subtract another rational from this one.
Upon return, *this = this + a.
a | rational decrement (input) |
Definition at line 354 of file Rational.h.
References Rational().
|
inline |
Subtract an integer from this rational.
Upon return, *this = this + a.
a | integer decrement (input) |
Definition at line 366 of file Rational.h.
References Rational().
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.
References Rational().
|
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.
References Rational().
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 Rational(), and 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 Rational(), and UTIL_THROW.
|
inline |
Return numerator.
Definition at line 431 of file Rational.h.
Referenced by operator*, operator+, operator+, operator-, operator-, operator-, operator/, and Rational().
|
inline |
Return denominator.
Definition at line 438 of file Rational.h.
Referenced by operator*, operator+, operator-, operator/, and Rational().
|
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.
Compute sum of two rationals.
a | 1st argument |
b | 2st argument |
Definition at line 490 of file Rational.h.
References den(), num(), and Rational().
Compute sum of rational and integer.
a | Rational argument |
b | integer argument |
Definition at line 505 of file Rational.h.
References num(), and Rational().
Compute difference of rationals.
a | 1st argument |
b | 2st argument |
Definition at line 530 of file Rational.h.
References den(), num(), and Rational().
Compute difference of rational and integer.
a | Rational argument |
b | integer argument |
Definition at line 545 of file Rational.h.
References num(), and Rational().
Compute difference of integer and rational.
b | integer argument |
a | Rational argument |
Definition at line 559 of file Rational.h.
References num(), and Rational().
Compute product of rationals.
Definition at line 573 of file Rational.h.
References den(), num(), and Rational().
Compute product of rational and integer.
a | Rational argument |
b | integer argument |
Definition at line 588 of file Rational.h.
References Rational().
Compute quotient of two rationals.
Definition at line 610 of file Rational.h.
References den(), num(), Rational(), and UTIL_THROW.
Compute quotient Rational divided by integer.
a | Rational argument (numerator) |
b | integer argument (denominator) |
Definition at line 628 of file Rational.h.
References Rational(), and UTIL_THROW.
Compute quotient integer divided by Rational.
b | integer argument (numerator) |
a | Rational argument (denominator) |
Definition at line 644 of file Rational.h.
References Rational(), and UTIL_THROW.
Equality operators.
Equality operator for two Rational numbers.
Definition at line 674 of file Rational.h.
References Rational().
|
friend |
Equality operator for a Rational and an integer.
a | Rational number |
b | integer number |
Definition at line 684 of file Rational.h.
References Rational().
Unary negation of Rational.
a | Rational number |
Definition at line 661 of file Rational.h.
References Rational().
|
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.
References Rational(), and UTIL_CHECK.