template class CCL::Math::Rational
Overview
#include <rational.h> template <class T> class Rational { public: // construction Rational (T numerator = 0, T denominator = 1); // methods Rational <T>& assign (T numerator, T denominator = 1); Rational <T>& setZero (); T getNumerator () const; T getDenominator () const; void setNumerator (int num); void setDenominator (int denom); float asFloat () const; double asDouble () const; Rational <T>& normalize (); bool denormalize (T denominator); bool operator == (const Rational <T>& b) const; bool operator != (const Rational <T>& b) const; bool operator < (const Rational <T>& b) const; bool operator > (const Rational <T>& b) const; bool operator <= (const Rational <T>& b) const; bool operator >= (const Rational <T>& b) const; Rational <T> operator + (const Rational <T>& b) const; Rational <T> operator - (const Rational <T>& b) const; Rational <T> operator * (const Rational <T>& b) const; Rational <T> operator/ (const Rational <T>& b) const; Rational <T>& operator += (const Rational <T>& b); Rational <T>& operator -= (const Rational <T>& b); Rational <T>& operator *= (const Rational <T>& b); Rational <T>& operator/= (const Rational <T>& b); };
Detailed Documentation
Construction
Rational (T numerator = 0, T denominator = 1)
Construcion and assigment.
Construct with numerator and denominator.
Methods
Rational <T>& assign (T numerator, T denominator = 1)
Assign new value.
T getNumerator () const
Accessors.
float asFloat () const
Conversion to decimal.
Compute decimal float value.
double asDouble () const
Compute decimal double value.
Rational <T>& normalize ()
Normalize rational number.
bool operator == (const Rational <T>& b) const
Comparison operators.
Equal.
bool operator != (const Rational <T>& b) const
Not equal.
bool operator < (const Rational <T>& b) const
Less than.
bool operator > (const Rational <T>& b) const
Greater than.
bool operator <= (const Rational <T>& b) const
Less or equal.
bool operator >= (const Rational <T>& b) const
Greater or equal.
Rational <T> operator + (const Rational <T>& b) const
Arithmetic operators.
Addition operator.
Rational <T> operator - (const Rational <T>& b) const
Subtraction operator.
Rational <T> operator * (const Rational <T>& b) const
Multiplication operator.
Rational <T> operator/ (const Rational <T>& b) const
Division operator.
Rational <T>& operator += (const Rational <T>& b)
Arithmetic assignment operators.
Addition assignment.
Rational <T>& operator -= (const Rational <T>& b)
Subtraction assignment.
Rational <T>& operator *= (const Rational <T>& b)
Multiplication assignment.
Rational <T>& operator/= (const Rational <T>& b)
Division assignment.