Effective implementation of algorithms (Master Thesis)
Effective and error-free implementation of algorithms
|
#include <rational.h>
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 |
T | numerator () const |
T | denominator () const |
void | normalize () |
Private Attributes | |
T | num |
T | 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) |
math::rational::Rational< T >::Rational | ( | ) | [inline] |
Constructor, creates zero
math::rational::Rational< T >::Rational | ( | T | value | ) | [inline] |
Constructor,
value | integer value of the rational number |
math::rational::Rational< T >::Rational | ( | T | n, |
T | d | ||
) | [inline] |
Constructor
n | numerator |
d | denominator |
math::rational::Rational< T >::Rational | ( | const Rational< T > & | value | ) | [inline] |
Copy constructor
math::rational::Rational< T >::C_ASSERT | ( | NumericType< T >::isInt | ) |
T math::rational::Rational< T >::denominator | ( | ) | const [inline] |
Rational<T> math::rational::Rational< T >::inverted | ( | ) | const [inline] |
void math::rational::Rational< T >::normalize | ( | ) | [inline] |
Normalize rational number. After this operation, numerator and demoninator will be coprime and denominator will be positive.
T math::rational::Rational< T >::numerator | ( | ) | const [inline] |
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.
Rational< T > operator+ | ( | const Rational< T > & | a, |
const Rational< T > & | b | ||
) | [related] |
Add two fractions
Rational< T > operator- | ( | const Rational< T > & | a, |
const Rational< T > & | b | ||
) | [related] |
Subtract two fractions
Rational< T > operator/ | ( | const Rational< T > & | a, |
const Rational< T > & | b | ||
) | [related] |
Divide two fractions
T math::rational::Rational< T >::den [private] |
denominator
T math::rational::Rational< T >::num [private] |
numerator