TRationalNumber< IntType > Class Template Reference
[Semiring]

Rational numbers class. More...

List of all members.

Public Member Functions

Standart constructors.

Default constructor.

 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

Set the numerator and the denominator.

TRationalNumberset (const IntType num, const IntType den=1)
Accessors

Get the numerator.

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

Usual Arithemetics 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

Implicit cast

 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

Fraction's numerator.

IntType num_
 Fraction's denominator.
IntType den_
 Fraction's denominator.

Detailed Description

template<typename IntType>
class vcsn::algebra::TRationalNumber< IntType >

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

Author:
David Moreira <david.moreira@epita.fr>

Definition at line 58 of file q_number.hh.


Member Function Documentation

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/=().