clipper
Public Member Functions | Static Public Member Functions | Private Member Functions | Static Private Member Functions | Private Attributes | Friends
Fraction Class Reference

Contains a pair of doubles signifying the numerator and denominator of a fraction. More...

List of all members.

Public Member Functions

 Fraction (double numerator=0, double denominator=1)
double numerator () const
double denominator () const
std::string toString () const
double toDouble () const
Fraction operator+ (const Fraction &b) const
Fraction operator- (const Fraction &b) const
Fraction operator* (const Fraction &b) const
Fraction operator/ (const Fraction &b) const
Fractionoperator+= (const Fraction &b)

Static Public Member Functions

static Fraction binomial (unsigned int n, unsigned int k)
 simple method to calculate binomial coefficients for small (n,k)

Private Member Functions

void reduce ()

Static Private Member Functions

static double gcd (double a, double b)
 Calculate the greatest common divisor using Euclid's algorithm.

Private Attributes

double m_numerator
double m_denominator

Friends

std::ostream & operator<< (std::ostream &os, const Fraction &f)

Detailed Description

Contains a pair of doubles signifying the numerator and denominator of a fraction.

The fraction can be printed using LaTeX syntax and many common operators are defined.

Definition at line 199 of file clipper.cc.


Constructor & Destructor Documentation

Fraction::Fraction ( double  numerator = 0,
double  denominator = 1 
) [inline]

Definition at line 227 of file clipper.cc.


Member Function Documentation

static Fraction Fraction::binomial ( unsigned int  n,
unsigned int  k 
) [inline, static]

simple method to calculate binomial coefficients for small (n,k)

Definition at line 294 of file clipper.cc.

double Fraction::denominator ( ) const [inline]

Definition at line 239 of file clipper.cc.

static double Fraction::gcd ( double  a,
double  b 
) [inline, static, private]

Calculate the greatest common divisor using Euclid's algorithm.

Definition at line 206 of file clipper.cc.

double Fraction::numerator ( ) const [inline]

Definition at line 234 of file clipper.cc.

Fraction Fraction::operator* ( const Fraction b) const [inline]

Definition at line 275 of file clipper.cc.

Fraction Fraction::operator+ ( const Fraction b) const [inline]

Definition at line 265 of file clipper.cc.

Fraction& Fraction::operator+= ( const Fraction b) [inline]

Definition at line 285 of file clipper.cc.

Fraction Fraction::operator- ( const Fraction b) const [inline]

Definition at line 270 of file clipper.cc.

Fraction Fraction::operator/ ( const Fraction b) const [inline]

Definition at line 280 of file clipper.cc.

void Fraction::reduce ( ) [inline, private]

Definition at line 214 of file clipper.cc.

double Fraction::toDouble ( ) const [inline]

Definition at line 260 of file clipper.cc.

std::string Fraction::toString ( ) const [inline]

Definition at line 244 of file clipper.cc.


Friends And Related Function Documentation

std::ostream& operator<< ( std::ostream &  os,
const Fraction f 
) [friend]

Definition at line 255 of file clipper.cc.


Member Data Documentation

double Fraction::m_denominator [private]

Definition at line 203 of file clipper.cc.

double Fraction::m_numerator [private]

Definition at line 202 of file clipper.cc.


The documentation for this class was generated from the following file:
 All Classes Files Functions Variables Typedefs Friends Defines