Rational numbers class. More...
Public Member Functions | |
Standart constructors. | |
TRationalNumber () | |
Constructor define numerator. Denominator set at 1. | |
TRationalNumber (const IntType num) | |
Constructor define numerator. Denominator set at 1. | |
TRationalNumber (const IntType num, const IntType den) | |
Constructor define numerator and denominator. | |
TRationalNumber (const TRationalNumber< IntType > &nb) | |
Copy Constructor. | |
~TRationalNumber () | |
Constructor define numerator. Denominator set at 1. | |
Setters | |
TRationalNumber & | set (const IntType num, const IntType den=1) |
Accessors | |
IntType | num_get () const |
Get the denominator. | |
IntType | den_get () const |
Get the denominator. | |
std::ostream & | print (std::ostream &ostr) const |
Printing method. | |
Usual Operator | |
TRationalNumber< IntType > | operator+ (const TRationalNumber< IntType > &nb) const |
Usual Boolean Opertor. | |
TRationalNumber< IntType > | operator- (const TRationalNumber< IntType > &nb) const |
Usual Boolean Opertor. | |
TRationalNumber< IntType > | operator- () const |
Usual Boolean Opertor. | |
TRationalNumber< IntType > | operator* (const TRationalNumber< IntType > &nb) const |
Usual Boolean Opertor. | |
TRationalNumber< IntType > | operator/ (const TRationalNumber< IntType > &nb) const |
Usual Boolean Opertor. | |
TRationalNumber< IntType > & | operator+= (const TRationalNumber< IntType > &nb) |
Usual Boolean Opertor. | |
TRationalNumber< IntType > & | operator-= (const TRationalNumber< IntType > &nb) |
Usual Boolean Opertor. | |
TRationalNumber< IntType > & | operator*= (const TRationalNumber< IntType > &nb) |
Usual Boolean Opertor. | |
TRationalNumber< IntType > & | operator/= (const TRationalNumber< IntType > &nb) |
Usual Boolean Opertor. | |
bool | operator== (const TRationalNumber< IntType > &nb) const |
Usual Boolean Opertor. | |
bool | operator!= (const TRationalNumber< IntType > &nb) const |
Usual Boolean Opertor. | |
bool | operator< (const TRationalNumber< IntType > &nb) const |
Usual Boolean Opertor. | |
bool | operator<= (const TRationalNumber< IntType > &nb) const |
Usual Boolean Opertor. | |
bool | operator> (const TRationalNumber< IntType > &nb) const |
Usual Boolean Opertor. | |
bool | operator>= (const TRationalNumber< IntType > &nb) const |
Usual Boolean Opertor. | |
Cast function | |
operator double () const | |
Explecit cast. | |
IntType | to_integer () const |
Explecit cast. | |
float | to_float () const |
Explecit cast. | |
double | to_double () const |
Explecit cast. | |
Protected Member Functions | |
Fraction simplification | |
void | set_rational () |
Simplifies the fraction Procedure set and simplifies the num_ and the den_ fraction. | |
void | set_rational (const IntType num, const IntType den) |
Simplifies the fraction Procedure set and simplifies the num_ and the den_ fraction. | |
void | set_unsafe_rational (const IntType num, const IntType den) |
Simplifies the fraction Procedure set and simplifies the num_ and the den_ fraction. | |
Protected Attributes | |
TRationalNumber<IntType> attributs | |
IntType | num_ |
Fraction's denominator. | |
IntType | den_ |
Fraction's denominator. |
Rational numbers class.
Implementation of rational numbers
Constructors are able to product simplified rational number.
Operation maintain num_ and den_ coprime.
num_ and den_ are always coprime
Definition at line 58 of file q_number.hh.
void set_rational | ( | ) | [inline, protected] |
Simplifies the fraction Procedure set and simplifies the num_ and the den_ fraction.
Set the num_ and the den_ with the following property : gcd (num_, den_) = 1
Definition at line 303 of file q_number.hxx.
References TRationalNumber< IntType >::den_, and TRationalNumber< IntType >::num_.
Referenced by TRationalNumber< IntType >::operator+=(), TRationalNumber< IntType >::operator-=(), and TRationalNumber< IntType >::TRationalNumber().
void set_rational | ( | const IntType | num, | |
const IntType | den | |||
) | [inline, protected] |
Simplifies the fraction Procedure set and simplifies the num_ and the den_ fraction.
Set the num_ and the den_ with the following property : gcd (num_, den_) = 1
Definition at line 279 of file q_number.hxx.
References TRationalNumber< IntType >::den_, vcsn::misc::gcd(), and TRationalNumber< IntType >::num_.
void set_unsafe_rational | ( | const IntType | num, | |
const IntType | den | |||
) | [inline, protected] |
Simplifies the fraction Procedure set and simplifies the num_ and the den_ fraction.
Set the num_ and the den_ with the following property : gcd (num_, den_) = 1
Definition at line 290 of file q_number.hxx.
References TRationalNumber< IntType >::den_, vcsn::misc::is_coprime(), and TRationalNumber< IntType >::num_.
Referenced by TRationalNumber< IntType >::operator*=(), and TRationalNumber< IntType >::operator/=().