# TRationalNumber< NUMType, DENType > 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 NUMType num)
| Constructor define numerator. Denominator set at 1.
| TRationalNumber (const NUMType num, const DENType den)
| Constructor define numerator and denominator.
| TRationalNumber (const TRationalNumber< NUMType, DENType > &nb)
| Copy Constructor.
| ~TRationalNumber ()
| Constructor define numerator. Denominator set at 1.
Setters
Set the numerator and the denominator.
TRationalNumber & | set (const NUMType num, const DENType den=1)
Accessors
Get the numerator.
NUMType | num_get () const
| Get the denominator.
DENType | den_get () const
| Get the denominator.
std::ostream & | print (std::ostream &ostr) const
| Printing method.
Usual Operator
Usual Arithemetics Operator.
TRationalNumber< NUMType, DENType > | operator+ (const TRationalNumber< NUMType, DENType > &nb) const
| Usual Boolean Opertor.
TRationalNumber< NUMType, DENType > | operator- (const TRationalNumber< NUMType, DENType > &nb) const
| Usual Boolean Opertor.
TRationalNumber< NUMType, DENType > | operator- () const
| Usual Boolean Opertor.
TRationalNumber< NUMType, DENType > | operator* (const TRationalNumber< NUMType, DENType > &nb) const
| Usual Boolean Opertor.
TRationalNumber< NUMType, DENType > | operator/ (const TRationalNumber< NUMType, DENType > &nb) const
| Usual Boolean Opertor.
TRationalNumber< NUMType, DENType > & | operator+= (const TRationalNumber< NUMType, DENType > &nb)
| Usual Boolean Opertor.
TRationalNumber< NUMType, DENType > & | operator-= (const TRationalNumber< NUMType, DENType > &nb)
| Usual Boolean Opertor.
TRationalNumber< NUMType, DENType > & | operator*= (const TRationalNumber< NUMType, DENType > &nb)
| Usual Boolean Opertor.
TRationalNumber< NUMType, DENType > & | operator/= (const TRationalNumber< NUMType, DENType > &nb)
| Usual Boolean Opertor.
bool | operator== (const TRationalNumber< NUMType, DENType > &nb) const
| Usual Boolean Opertor.
bool | operator!= (const TRationalNumber< NUMType, DENType > &nb) const
| Usual Boolean Opertor.
bool | operator< (const TRationalNumber< NUMType, DENType > &nb) const
| Usual Boolean Opertor.
bool | operator<= (const TRationalNumber< NUMType, DENType > &nb) const
| Usual Boolean Opertor.
bool | operator> (const TRationalNumber< NUMType, DENType > &nb) const
| Usual Boolean Opertor.
bool | operator>= (const TRationalNumber< NUMType, DENType > &nb) const
| Usual Boolean Opertor.
Cast function
Implicit cast
| operator float () const
| Explecit cast.
int | to_int () 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 NUMType num, const DENType den)
| Simplifies the fraction Procedure set and simplifies the num_ and the den_ fraction.
void | set_unsafe_rational (const NUMType num, const DENType den)
| Simplifies the fraction Procedure set and simplifies the num_ and the den_ fraction.

## Protected Attributes

TRationalNumber<NUMType, DENType> attributs
Fraction's numerator.
NUMType | num_
| Fraction's denominator.
DENType | den_
| Fraction's denominator.

## Detailed Description

### template<typename NUMType, typename DENType>
class vcsn::algebra::TRationalNumber< NUMType, DENType >

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 338 of file q_number.hxx.

References TRationalNumber< NUMType, DENType >::den_, and TRationalNumber< NUMType, DENType >::num_.

Referenced by TRationalNumber< NUMType, DENType >::operator+=(), TRationalNumber< NUMType, DENType >::operator-=(), and TRationalNumber< NUMType, DENType >::TRationalNumber().

void set_rational | ( | const NUMType | num,
|  | const DENType | 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 296 of file q_number.hxx.

References vcsn::misc::abs(), TRationalNumber< NUMType, DENType >::den_, vcsn::misc::gcd(), and TRationalNumber< NUMType, DENType >::num_.

void set_unsafe_rational | ( | const NUMType | num,
|  | const DENType | 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 325 of file q_number.hxx.

References TRationalNumber< NUMType, DENType >::den_, vcsn::misc::is_coprime(), and TRationalNumber< NUMType, DENType >::num_.

Referenced by TRationalNumber< NUMType, DENType >::operator*=(), and TRationalNumber< NUMType, DENType >::operator/=().