The class rational represents rational number. More...
#include <rational.hh>
Public Member Functions  
rational (int n=0, int d=1)  
Constructor.  
void  set_denom (int d) 
Expand fraction to given denominator.  
rational &  cancel () 
Cancel common factors from the fraction.  
rational &  operator*= (const rational &other) 
Multiplication.  
rational  operator (const rational &other) const 
Difference.  
bool  operator! () const 
Implicit conversion to bool and negation.  
bool  operator== (const rational &other) const 
bool  operator< (const rational &other) const 
bool  operator<= (const rational &other) const 
bool  operator!= (const rational &other) const 
bool  operator>= (const rational &other) const 
bool  operator> (const rational &other) const 
Public Attributes  
int  nom 
Nomionator.  
int  denom 
Denominator. 
The class rational represents rational number.
A rational number is represented by giving a nominator and a denominator. Common factors need not necessarily be canceled from the fraction.
Definition at line 38 of file rational.hh.
rational::rational  (  int  n = 0 , 

int  d = 1  
)  [inline] 
Constructor.
Depending on the number of arguments, this constructor can represent the default value of zero, an integer with denominator one, or a full fraction with nominator and denominator.
n  the nominator of the rational number  
d  the denominator of the rational number 
Definition at line 61 of file rational.hh.
Referenced by operator().
rational & rational::cancel  (  ) 
Cancel common factors from the fraction.
This is done by dividing both nominator and denominator by their greatest common divisor.
Definition at line 51 of file rational.cc.
References denom, gcd(), and nom.
Referenced by operator*=().
bool rational::operator!  (  )  const [inline] 
Implicit conversion to bool and negation.
true
if the nominator is zero. Definition at line 83 of file rational.hh.
References nom.
Multiplication.
other  the second factor. 
this
* other
. Definition at line 63 of file rational.cc.
Difference.
other  the subtrahend of the difference. 
this
 other
. Definition at line 75 of file rational.cc.
References denom, lcm(), nom, and rational().
void rational::set_denom  (  int  d  )  [inline] 
Expand fraction to given denominator.
The new denominator must be a multiple of the current denominator. The intended use is to calculate the common denominator of a set of rationals and then expand each member of the set to this denominator.
d  the new denominator, multiple of current denominator 
Definition at line 73 of file rational.hh.