Effective implementation of algorithms (Master Thesis)
Effective and error-free implementation of algorithms
math::rational::Rational< T > Class Template Reference

#include <rational.h>

List of all members.

Public Member Functions

 C_ASSERT (NumericType< T >::isInt)
 Rational ()
 Rational (T value)
 Rational (T n, T d)
 Rational (const Rational< T > &value)
Rational< T > inverted () const
numerator () const
denominator () const
void normalize ()

Private Attributes

num
den

Related Functions

(Note that these are not member functions.)

template<typename T >
Rational< T > operator* (const Rational< T > &a, const Rational< T > &b)
template<typename T >
Rational< T > operator/ (const Rational< T > &a, const Rational< T > &b)
template<typename T >
Rational< T > operator+ (const Rational< T > &a, const Rational< T > &b)
template<typename T >
Rational< T > operator- (const Rational< T > &a, const Rational< T > &b)

template<typename T>
class math::rational::Rational< T >


Constructor & Destructor Documentation

template<typename T>
math::rational::Rational< T >::Rational ( ) [inline]

Constructor, creates zero

template<typename T>
math::rational::Rational< T >::Rational ( value) [inline]

Constructor,

Parameters:
valueinteger value of the rational number
template<typename T>
math::rational::Rational< T >::Rational ( n,
d 
) [inline]

Constructor

Parameters:
nnumerator
ddenominator
template<typename T>
math::rational::Rational< T >::Rational ( const Rational< T > &  value) [inline]

Copy constructor


Member Function Documentation

template<typename T>
math::rational::Rational< T >::C_ASSERT ( NumericType< T >::isInt  )
template<typename T>
T math::rational::Rational< T >::denominator ( ) const [inline]
Returns:
denominator
template<typename T>
Rational<T> math::rational::Rational< T >::inverted ( ) const [inline]
Returns:
inverse number 1/x
template<typename T>
void math::rational::Rational< T >::normalize ( ) [inline]

Normalize rational number. After this operation, numerator and demoninator will be coprime and denominator will be positive.

template<typename T>
T math::rational::Rational< T >::numerator ( ) const [inline]
Returns:
numerator

Friends And Related Function Documentation

template<typename T >
Rational< T > operator* ( const Rational< T > &  a,
const Rational< T > &  b 
) [related]

Multiply two fractions

Note: there exists slight optimization of multiplication - for normalized fractions (a/b) and (c/d) multiplication (a/b) * (c/d) may be written as normalize(c/b) * normalize(a/d) hovewer we will not use it here.

Returns:
a*b
template<typename T >
Rational< T > operator+ ( const Rational< T > &  a,
const Rational< T > &  b 
) [related]

Add two fractions

Returns:
a + b
template<typename T >
Rational< T > operator- ( const Rational< T > &  a,
const Rational< T > &  b 
) [related]

Subtract two fractions

Returns:
a - b
template<typename T >
Rational< T > operator/ ( const Rational< T > &  a,
const Rational< T > &  b 
) [related]

Divide two fractions

Returns:
a / b

Member Data Documentation

template<typename T>
T math::rational::Rational< T >::den [private]

denominator

template<typename T>
T math::rational::Rational< T >::num [private]

numerator


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