xoreos  0.0.5
Public Member Functions | Private Member Functions | Private Attributes | List of all members
Common::Rational Class Reference

A simple rational class that holds fractions. More...

#include <rational.h>

Public Member Functions

 Rational ()
 
 Rational (int num)
 
 Rational (int num, int denom)
 
Rationaloperator= (const Rational &right)
 
Rationaloperator= (int right)
 
Rationaloperator+= (const Rational &right)
 
Rationaloperator-= (const Rational &right)
 
Rationaloperator*= (const Rational &right)
 
Rationaloperator/= (const Rational &right)
 
Rationaloperator+= (int right)
 
Rationaloperator-= (int right)
 
Rationaloperator*= (int right)
 
Rationaloperator/= (int right)
 
const Rational operator- () const
 
const Rational operator+ (const Rational &right) const
 
const Rational operator- (const Rational &right) const
 
const Rational operator* (const Rational &right) const
 
const Rational operator/ (const Rational &right) const
 
const Rational operator+ (int right) const
 
const Rational operator- (int right) const
 
const Rational operator* (int right) const
 
const Rational operator/ (int right) const
 
bool operator== (const Rational &right) const
 
bool operator!= (const Rational &right) const
 
bool operator> (const Rational &right) const
 
bool operator< (const Rational &right) const
 
bool operator>= (const Rational &right) const
 
bool operator<= (const Rational &right) const
 
bool operator== (int right) const
 
bool operator!= (int right) const
 
bool operator> (int right) const
 
bool operator< (int right) const
 
bool operator>= (int right) const
 
bool operator<= (int right) const
 
void invert ()
 
Rational getInverse () const
 
int toInt () const
 
double toDouble () const
 
int getNumerator () const
 
int getDenominator () const
 

Private Member Functions

void cancel ()
 

Private Attributes

int _num
 
int _denom
 

Detailed Description

A simple rational class that holds fractions.

Definition at line 56 of file rational.h.

Constructor & Destructor Documentation

◆ Rational() [1/3]

Common::Rational::Rational ( )

Definition at line 56 of file rational.cpp.

References _denom, and _num.

Referenced by operator*=(), operator+=(), operator-(), operator-=(), operator/=(), operator<(), operator<=(), operator>(), and operator>=().

Here is the caller graph for this function:

◆ Rational() [2/3]

Common::Rational::Rational ( int  num)

Definition at line 61 of file rational.cpp.

References _denom, and _num.

◆ Rational() [3/3]

Common::Rational::Rational ( int  num,
int  denom 
)

Definition at line 66 of file rational.cpp.

References _denom, _num, and cancel().

Here is the call graph for this function:

Member Function Documentation

◆ cancel()

void Common::Rational::cancel ( )
private

Definition at line 81 of file rational.cpp.

References _denom, _num, and Common::gcd().

Referenced by operator+=(), operator-=(), and Rational().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getDenominator()

int Common::Rational::getDenominator ( ) const
inline

Definition at line 108 of file rational.h.

References _denom.

Referenced by Common::Timestamp::Timestamp().

Here is the caller graph for this function:

◆ getInverse()

Rational Common::Rational::getInverse ( ) const

Definition at line 279 of file rational.cpp.

References inverse().

Referenced by operator/=(), and Common::Timestamp::Timestamp().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getNumerator()

int Common::Rational::getNumerator ( ) const
inline

Definition at line 107 of file rational.h.

References _num.

Referenced by Common::Timestamp::Timestamp().

Here is the caller graph for this function:

◆ invert()

void Common::Rational::invert ( )

Definition at line 267 of file rational.cpp.

References _denom, and _num.

◆ operator!=() [1/2]

bool Common::Rational::operator!= ( const Rational right) const

Definition at line 223 of file rational.cpp.

References _denom, and _num.

◆ operator!=() [2/2]

bool Common::Rational::operator!= ( int  right) const

Definition at line 247 of file rational.cpp.

References _denom, and _num.

◆ operator*() [1/2]

const Rational Common::Rational::operator* ( const Rational right) const

Definition at line 183 of file rational.cpp.

◆ operator*() [2/2]

const Rational Common::Rational::operator* ( int  right) const

Definition at line 207 of file rational.cpp.

◆ operator*=() [1/2]

Rational & Common::Rational::operator*= ( const Rational right)

Definition at line 135 of file rational.cpp.

References _denom, _num, and Common::gcd().

Here is the call graph for this function:

◆ operator*=() [2/2]

Rational & Common::Rational::operator*= ( int  right)

Definition at line 159 of file rational.cpp.

References Rational().

Here is the call graph for this function:

◆ operator+() [1/2]

const Rational Common::Rational::operator+ ( const Rational right) const

Definition at line 171 of file rational.cpp.

◆ operator+() [2/2]

const Rational Common::Rational::operator+ ( int  right) const

Definition at line 195 of file rational.cpp.

◆ operator+=() [1/2]

Rational & Common::Rational::operator+= ( const Rational right)

Definition at line 105 of file rational.cpp.

References _denom, _num, cancel(), and Common::gcd().

Here is the call graph for this function:

◆ operator+=() [2/2]

Rational & Common::Rational::operator+= ( int  right)

Definition at line 151 of file rational.cpp.

References Rational().

Here is the call graph for this function:

◆ operator-() [1/3]

const Rational Common::Rational::operator- ( ) const

Definition at line 167 of file rational.cpp.

References _denom, _num, and Rational().

Here is the call graph for this function:

◆ operator-() [2/3]

const Rational Common::Rational::operator- ( const Rational right) const

Definition at line 177 of file rational.cpp.

◆ operator-() [3/3]

const Rational Common::Rational::operator- ( int  right) const

Definition at line 201 of file rational.cpp.

◆ operator-=() [1/2]

Rational & Common::Rational::operator-= ( const Rational right)

Definition at line 120 of file rational.cpp.

References _denom, _num, cancel(), and Common::gcd().

Here is the call graph for this function:

◆ operator-=() [2/2]

Rational & Common::Rational::operator-= ( int  right)

Definition at line 155 of file rational.cpp.

References Rational().

Here is the call graph for this function:

◆ operator/() [1/2]

const Rational Common::Rational::operator/ ( const Rational right) const

Definition at line 189 of file rational.cpp.

◆ operator/() [2/2]

const Rational Common::Rational::operator/ ( int  right) const

Definition at line 213 of file rational.cpp.

◆ operator/=() [1/2]

Rational & Common::Rational::operator/= ( const Rational right)

Definition at line 147 of file rational.cpp.

References getInverse().

Here is the call graph for this function:

◆ operator/=() [2/2]

Rational & Common::Rational::operator/= ( int  right)

Definition at line 163 of file rational.cpp.

References Rational().

Here is the call graph for this function:

◆ operator<() [1/2]

bool Common::Rational::operator< ( const Rational right) const

Definition at line 231 of file rational.cpp.

References _denom, and _num.

◆ operator<() [2/2]

bool Common::Rational::operator< ( int  right) const

Definition at line 255 of file rational.cpp.

References Rational().

Here is the call graph for this function:

◆ operator<=() [1/2]

bool Common::Rational::operator<= ( const Rational right) const

Definition at line 239 of file rational.cpp.

References _denom, and _num.

◆ operator<=() [2/2]

bool Common::Rational::operator<= ( int  right) const

Definition at line 263 of file rational.cpp.

References Rational().

Here is the call graph for this function:

◆ operator=() [1/2]

Rational & Common::Rational::operator= ( const Rational right)

Definition at line 91 of file rational.cpp.

References _denom, and _num.

◆ operator=() [2/2]

Rational & Common::Rational::operator= ( int  right)

Definition at line 98 of file rational.cpp.

References _denom, and _num.

◆ operator==() [1/2]

bool Common::Rational::operator== ( const Rational right) const

Definition at line 219 of file rational.cpp.

References _denom, and _num.

◆ operator==() [2/2]

bool Common::Rational::operator== ( int  right) const

Definition at line 243 of file rational.cpp.

References _denom, and _num.

◆ operator>() [1/2]

bool Common::Rational::operator> ( const Rational right) const

Definition at line 227 of file rational.cpp.

References _denom, and _num.

◆ operator>() [2/2]

bool Common::Rational::operator> ( int  right) const

Definition at line 251 of file rational.cpp.

References Rational().

Here is the call graph for this function:

◆ operator>=() [1/2]

bool Common::Rational::operator>= ( const Rational right) const

Definition at line 235 of file rational.cpp.

References _denom, and _num.

◆ operator>=() [2/2]

bool Common::Rational::operator>= ( int  right) const

Definition at line 259 of file rational.cpp.

References Rational().

Here is the call graph for this function:

◆ toDouble()

double Common::Rational::toDouble ( ) const

Definition at line 291 of file rational.cpp.

References _denom, and _num.

◆ toInt()

int Common::Rational::toInt ( ) const

Definition at line 287 of file rational.cpp.

References _denom, and _num.

Member Data Documentation

◆ _denom

int Common::Rational::_denom
private

◆ _num

int Common::Rational::_num
private

The documentation for this class was generated from the following files: