Rational: A rational number based on an arbitrary precision integer

 

class Rational : public Moveable<Rational

 

A rational number based on an arbitrary precision integer type based on intInf.

Arbitrary precision means that the type is never out of bounds.

A rational number means that it is a fraction of a numerator and denominator.

The goal of this focus is to allow to handle almost infinite precision lossless floating numbers

This feature comes with a huge performance penalty.

 

Constructor Detail


 

Rational()

Class default constructor.

 


 

Rational(const Rational& v)

Copy constructor based on v..

 


 

template <typename TRational(T v)

Constructor based in v..

 


 

template <typename TRational(T n, T d)

Constructor based in numerator n and denominator d..

 


 

Rational(double n, double d)

Constructor based on double numerator n and denominator d.

 

Public Member List


 

Rational operator-() const

MInus sign.

 


 

bool operator<(const Rational& rightconst

Logical lower than Rational right operator.

 


 

template <typename Tbool operator<(const T& rightconst

Logical lower than right operator.

 


 

bool operator>(const Rational& rightconst

Logical upper than  right operator.

 


 

template <typename Tbool operator>(const T& rightconst

Logical upper than right operator.

 


 

template <typename Tconst Rational& operator=(T v)

Assignment operator from v.

 


 

const Rational& operator=(double d)

Assignment operator from  d.

 


 

void operator++()

Operator increment

 


 

void operator--()

Operator decrement

 


 

void operator+=(const Rational& right)

Operator increment with right.

 


 

void operator-=(const Rational& right)

Operator decrement with right.

 


 

void operator*=(const Rational& right)

Operator multiply by right.

 


 

void operator/=(const Rational& right)

Operator divide between right.

 


 

bool operator==(Rational& rightconst

Logical operator equal to right.

 


 

template <typename Tbool operator==(T rightconst

Logical operator equal to  right.

 


 

bool operator!=(Rational& rightconst

Logical operator different to  right .

 


 

template <typename Tbool operator!=(T rightconst

Logical operator different to  right .

 


 

template <typename Toperator T()

Operator cast.

 


 

operator double()

Operator cast to double

 


 

Rational Simplify(bool full = false)

Simplify fraction. If full is set, it simplifies using all possible values.

This operation may be very slow

 


 

String ToString() const

Conversion to String.

 

Public Member List


 

Rational abs()

Gets absolute value.

 


 

Rational pow(int e)

Gets rational raised to integer e.

 


 

Rational sqrt()

Approximate square root.

 


 

String FormatRational(const Rational &d, int numDec)

Gets an String of rational d. numDec .indicates the floating point number of decimals. If numDec is Null, String is shown as a fraction.