Rational class implements standard methods and data structures to manipulate Rational ratios arithmetically. More...
#include <Rational.h>
Public Member Functions | |
Rational () | |
Default constructor. | |
Rational (Integer i) | |
Default constructor. | |
Rational (Const Rational &x) | |
Copy constructor. | |
Rational (Real x) | |
Construct Rational given a fractional value. | |
Rational (Integer num, Integer den) | |
Construct Rational given a rational fraction value. | |
Rational (Real x, Integer &num, Integer &den) | |
Construct Rational given a Real fractional value, determine its rational approximation, assign numerator and denominator to reference arguments. | |
Rational (Rational x, Integer &num, Integer &den) | |
Construct Rational given a Rational, determine its rational approximation, assign numerator and denominator to reference arguments. | |
Rational & | operator= (Const Rational &x) |
Rational assignment operator. | |
Bool | operator== (Const Rational &x) Const |
Rational equality operator. | |
Bool | operator!= (Const Rational &x) Const |
Rational inequality operator. | |
Bool | operator>= (Const Rational &x) Const |
Rational >= operator. | |
Bool | operator> (Const Rational &x) Const |
Rational > operator. | |
Bool | operator< (Const Rational &x) Const |
Rational < operator. | |
Bool | operator<= (Const Rational &x) Const |
Rational <= operator. | |
Rational & | operator+= (Const Real x) |
Rational plus-equals operator. | |
Rational & | operator+= (Rational x) |
Rational plus-equals operator. | |
Rational & | operator-= (Const Real x) |
Rational minus-equals operator. | |
Rational & | operator-= (Rational x) |
Rational minus-equals operator. | |
Rational & | operator*= (Const Real x) |
Rational times-equals operator. | |
Rational & | operator*= (Rational x) |
Rational times-equals operator. | |
Rational & | operator/= (Const Real x) |
Rational divide-equals operator. | |
Rational & | operator/= (Rational x) |
Rational divide-equals operator. | |
Rational | operator+ (Rational &x) |
Rational addition operator. | |
Rational | operator- (Rational &x) |
Rational subtraction operator. | |
Rational | operator* (Rational &x) |
Rational times operator. | |
Rational | operator/ (Rational &x) |
Rational divide operator. | |
Rational | operator+ (Const Real x) |
Rational add to Real operator. | |
Rational | operator- (Const Real x) |
Rational subtract from Real operator. | |
Rational | operator* (Const Real x) |
Rational multiply by Real operator. | |
Rational | operator/ (Const Real x) |
Rational divide by Real operator. | |
String | print (String s=0) Const |
Print Rational prefixed by String. | |
Protected Attributes | |
Integer | m_num |
Integer | m_den |
Static char | s_buf [128] |
Friends | |
ostream & | operator<< (ostream &, Rational &) |
istream & | operator>> (istream &is, Rational &p) |
Bool | operator== (Integer &i, Rational &p) |
Bool | operator== (Rational &p, Integer &i) |
Bool | operator!= (Integer &i, Rational &p) |
Bool | operator!= (Rational &p, Integer &i) |
Bool | operator>= (Rational &p, Integer &r) |
Bool | operator>= (Integer &i, Rational &p) |
Bool | operator> (Rational &p, Integer &i) |
Bool | operator> (Integer &i, Rational &p) |
Bool | operator<= (Rational &p, Integer &i) |
Bool | operator<= (Integer &i, Rational &p) |
Bool | operator== (Real &r, Rational &p) |
Bool | operator== (Rational &p, Real &r) |
Bool | operator!= (Real &r, Rational &p) |
Bool | operator!= (Rational &p, Real &r) |
Bool | operator>= (Rational &p, Real &r) |
Bool | operator>= (Real &r, Rational &p) |
Bool | operator> (Rational &p, Real &r) |
Bool | operator> (Real &r, Rational &p) |
Bool | operator<= (Rational &p, Real &r) |
Bool | operator<= (Real &r, Rational &p) |
Rational class implements standard methods and data structures to manipulate Rational ratios arithmetically.
Definition at line 32 of file Rational.h.
Rational::Rational | ( | ) | [inline] |
Default constructor.
Definition at line 62 of file Rational.h.
Referenced by operator*(), operator+(), operator+=(), operator-(), and operator/().
Rational::Rational | ( | Integer | i ) | [inline] |
Rational::Rational | ( | Const Rational & | x ) | [inline] |
Rational::Rational | ( | Real | x ) | [inline] |
Construct Rational given a fractional value.
x | Rational fraction expressed as a Real |
Definition at line 72 of file Rational.h.
References m_den, m_num, and RealToRational().
: m_num(0), m_den(0) { RealToRational( x, m_num, m_den ); }
Construct Rational given a Real fractional value, determine its rational approximation, assign numerator and denominator to reference arguments.
x | Real fractional reference value |
num | Reference Integer numerator of derived rational fraction approximation |
den | Reference Integer denominator of derived rational fraction approximation |
Definition at line 86 of file Rational.h.
References m_den, m_num, and RealToRational().
: m_num(0), m_den(0) { RealToRational( x, num, den ); m_num = num; m_den = den; }
Construct Rational given a Rational, determine its rational approximation, assign numerator and denominator to reference arguments.
x | Rational value |
num | Reference Integer numerator of derived rational fraction approximation |
den | Reference Integer denominator of derived rational fraction approximation |
Definition at line 96 of file Rational.h.
References m_den, m_num, and RealToRational().
: m_num(0), m_den(0) { RealToRational( x.quotient(), num, den ); m_num = num; m_den = den; }
Rational times operator.
Definition at line 190 of file Rational.h.
References Rational(), and Return.
Rational multiply by Real operator.
Definition at line 210 of file Rational.h.
References Rational(), and Return.
Rational times-equals operator.
Definition at line 160 of file Rational.h.
References Return.
{ Return( *this = quotient() * x ); }
Rational times-equals operator.
Definition at line 165 of file Rational.h.
References Return.
{ Return( *this = quotient() * x.quotient() ); }
Rational addition operator.
Definition at line 180 of file Rational.h.
References Rational(), and Return.
Rational add to Real operator.
Definition at line 200 of file Rational.h.
References Rational(), and Return.
Rational plus-equals operator.
Definition at line 145 of file Rational.h.
References Rational(), and Return.
Rational plus-equals operator.
Definition at line 140 of file Rational.h.
References Rational(), and Return.
Rational subtraction operator.
Definition at line 185 of file Rational.h.
References Rational(), and Return.
Rational subtract from Real operator.
Definition at line 205 of file Rational.h.
References Rational(), and Return.
Rational minus-equals operator.
Definition at line 155 of file Rational.h.
References Return.
{ Return( *this = quotient() - x.quotient() ); }
Rational minus-equals operator.
Definition at line 150 of file Rational.h.
References Return.
{ Return( *this = quotient() - x ); }
Rational divide by Real operator.
Definition at line 215 of file Rational.h.
References Rational(), and Return.
Rational divide operator.
Definition at line 195 of file Rational.h.
References Rational(), and Return.
Rational divide-equals operator.
Definition at line 175 of file Rational.h.
References Return.
{ Return( *this = quotient() / x.quotient() ); }
Rational divide-equals operator.
Definition at line 170 of file Rational.h.
References Return.
{ Return( *this = quotient() / x ); }
Rational < operator.
Definition at line 130 of file Rational.h.
References Return.
{ Return quotient() < x.quotient(); }
Rational <= operator.
Definition at line 135 of file Rational.h.
References Return.
{ Return quotient() <= x.quotient(); }
Rational > operator.
Definition at line 125 of file Rational.h.
References Return.
{ Return quotient() > x.quotient(); }
Rational >= operator.
Definition at line 120 of file Rational.h.
References Return.
{ Return quotient() >= x.quotient(); }
Print Rational prefixed by String.
s | Prefix string |
Definition at line 221 of file Rational.h.
References If, m_den, m_num, Return, and s_buf.
Referenced by operator<<().
{ If (s) cout << s; #ifdef _MSC_VER // Disable Microsoft Visual Studio warning about sprintf() // until is universal agreement about how to handle its insecurities #pragma warning(push) #pragma warning(disable: 4996) sprintf(s_buf, "{%d,%d}", m_num, m_den); #pragma warning(pop) #else sprintf(s_buf, "{%d,%d}", m_num, m_den); #endif Return s_buf; }
Definition at line 39 of file Rational.h.
{ Return i != p.quotient(); }
Definition at line 51 of file Rational.h.
{ Return p.quotient() != r; }
Definition at line 40 of file Rational.h.
{ Return p.quotient() != i; }
Definition at line 50 of file Rational.h.
{ Return r != p.quotient(); }
ostream& operator<< | ( | ostream & | os, |
Rational & | r | ||
) | [friend] |
Definition at line 21 of file Rational.cpp.
Definition at line 45 of file Rational.h.
{ Return p.quotient() <= i; }
Definition at line 56 of file Rational.h.
{ Return p.quotient() <= r; }
Definition at line 57 of file Rational.h.
{ Return r <= p.quotient(); }
Definition at line 46 of file Rational.h.
{ Return i <= p.quotient(); }
Definition at line 38 of file Rational.h.
{ Return p.quotient() == i; }
Definition at line 37 of file Rational.h.
{ Return i == p.quotient(); }
Definition at line 48 of file Rational.h.
{ Return r == p.quotient(); }
Definition at line 49 of file Rational.h.
{ Return p.quotient() == r; }
Definition at line 43 of file Rational.h.
{ Return p.quotient() > i; }
Definition at line 54 of file Rational.h.
{ Return p.quotient() > r; }
Definition at line 44 of file Rational.h.
{ Return i > p.quotient(); }
Definition at line 55 of file Rational.h.
{ Return r > p.quotient(); }
Definition at line 41 of file Rational.h.
{ Return p.quotient() >= r; }
Definition at line 52 of file Rational.h.
{ Return p.quotient() >= r; }
Definition at line 42 of file Rational.h.
{ Return i >= p.quotient(); }
Definition at line 53 of file Rational.h.
{ Return r >= p.quotient(); }
istream& operator>> | ( | istream & | is, |
Rational & | p | ||
) | [friend] |
Definition at line 27 of file Rational.cpp.
Integer Rational::m_den [protected] |
Definition at line 244 of file Rational.h.
Referenced by operator!=(), operator=(), operator==(), operator>>(), print(), and Rational().
Integer Rational::m_num [protected] |
Definition at line 243 of file Rational.h.
Referenced by operator!=(), operator=(), operator==(), operator>>(), print(), and Rational().
Character Rational::s_buf [protected] |
Definition at line 245 of file Rational.h.
Referenced by print().