Givaro
Public Types | Public Member Functions | Static Public Member Functions | Protected Types | Protected Member Functions | Protected Attributes | Static Protected Attributes | Friends
Rationel Class Reference

#include <gmp++_rat.h>

Public Types

enum  reduceFlag { Reduce = 0x1, NoReduce = 0x0 }

Public Member Functions

giv_all_inlined Rationel ()
 default constructor (0/1).
 ~Rationel ()
 Destructor.
giv_all_inlined Rationelnegin ()
giv_all_inlined operator std::string () const
giv_all_inlined Integer getDenom () const
 Gets the denominator of a Rationel.
giv_all_inlined Integer getNumer () const
 Gets the numerator of a Rationel.
giv_all_inlined mpq_ptr get_mpq ()
 Retrieve the GMP representation of a Rationel.
giv_all_inlined mpq_srcptr get_mpq_const () const
giv_all_inlined mpz_ptr get_mpq_den () const
 Retrieve the GMP representation of the denominator of a Rationel.
giv_all_inlined mpz_ptr get_mpq_num () const
 Retrieve the GMP representation of the numerator of a Rationel.
giv_all_inlined Rationelreduce ()
 Reduces (inplace) a fraction to a canonical representation.
giv_all_inlined int isZero ()
giv_all_inlined Rationellogcpy (const Rationel &n)
giv_all_inlined Rationeloperator= (const Rationel &n)
giv_all_inlined Rationeloperator= (const Integer &n)
giv_all_inlined Rationel (Integer &n)
 constructors from a single numerator.
giv_all_inlined Rationel (int n)
 constructors from a single numerator.
giv_all_inlined Rationel (unsigned int n)
 constructors from a single numerator.
giv_all_inlined Rationel (long int n)
 constructors from a single numerator.
giv_all_inlined Rationel (long unsigned int n)
 constructors from a single numerator.
giv_all_inlined Rationel (Integer &n, Integer &d, enum reduceFlag=NoReduce)
 constructors from a numerator and a denominator.
giv_all_inlined Rationel (int n, int d, enum reduceFlag=NoReduce)
 constructors from a numerator and a denominator.
giv_all_inlined Rationel (unsigned int n, int d, enum reduceFlag=NoReduce)
 constructors from a numerator and a denominator.
giv_all_inlined Rationel (long int n, int d, enum reduceFlag=NoReduce)
 constructors from a numerator and a denominator.
giv_all_inlined Rationel (long unsigned int n, int d, enum reduceFlag=NoReduce)
 constructors from a numerator and a denominator.
giv_all_inlined Rationel (int n, unsigned int d, enum reduceFlag=NoReduce)
 constructors from a numerator and a denominator.
giv_all_inlined Rationel (int n, long int d, enum reduceFlag=NoReduce)
 constructors from a numerator and a denominator.
giv_all_inlined Rationel (int n, long unsigned int d, enum reduceFlag=NoReduce)
 constructors from a numerator and a denominator.
giv_all_inlined Rationel (unsigned int n, unsigned int d, enum reduceFlag=NoReduce)
 constructors from a numerator and a denominator.
giv_all_inlined Rationel (unsigned int n, long int d, enum reduceFlag=NoReduce)
 constructors from a numerator and a denominator.
giv_all_inlined Rationel (unsigned int n, long unsigned int d, enum reduceFlag=NoReduce)
 constructors from a numerator and a denominator.
giv_all_inlined Rationel (long unsigned int n, unsigned int d, enum reduceFlag=NoReduce)
 constructors from a numerator and a denominator.
giv_all_inlined Rationel (long int n, unsigned int d, enum reduceFlag=NoReduce)
 constructors from a numerator and a denominator.
giv_all_inlined Rationel (long int n, long int d, enum reduceFlag=NoReduce)
 constructors from a numerator and a denominator.
giv_all_inlined Rationel (long unsigned int n, long int d, enum reduceFlag=NoReduce)
 constructors from a numerator and a denominator.
giv_all_inlined Rationel (long int n, long unsigned int d, enum reduceFlag=NoReduce)
 constructors from a numerator and a denominator.
giv_all_inlined Rationel (long unsigned int n, long unsigned int d, enum reduceFlag=NoReduce)
 constructors from a numerator and a denominator.
template<class T >
giv_all_inlined Rationel (Integer &n, T d, enum reduceFlag=NoReduce)
template<class T >
giv_all_inlined Rationel (T n, Integer &d, enum reduceFlag=NoReduce)
template<class T , class U >
giv_all_inlined Rationel (T n, U d, enum reduceFlag=NoReduce)
template<class T , class U >
giv_all_inlined Rationel (T &n, U &d, enum reduceFlag=NoReduce)
giv_all_inlined Rationel (Rationel &f, enum reduceFlag=NoReduce)
 constructors from another Rationel
giv_all_inlined Rationel (float f, enum reduceFlag=NoReduce)
 constructors from another Rationel
giv_all_inlined Rationel (double f, enum reduceFlag=NoReduce)
 constructors from another Rationel
giv_all_inlined Rationel (long double f, enum reduceFlag=NoReduce)
 constructors from another Rationel

Static Public Member Functions

static giv_all_inlined Rationeladdin (Rationel &res, const Rationel &n)
static giv_all_inlined Rationeladdin (Rationel &res, const Integer &n)
static giv_all_inlined Rationelnegin (Rationel &res)
static giv_all_inlined Rationelreduce (Rationel &r)
 Reduces a fraction to a canonical representation.
static int isZero (const Rationel &n)
static giv_all_inlined void setInteger (Rationel &f, const Integer &n)

Protected Types

typedef __mpq_struct Rep
typedef __mpz_struct RawRep

Protected Member Functions

int privSign () const
const Repget_rep () const

Protected Attributes

Rep gmp_rep
RawRepnum
RawRepden

Static Protected Attributes

static reduceFlag flags
 flag that indicates reduction is done or not after an operation.

Friends

giv_all_inlined Rationel abs (const Rationel &n)

I/O

giv_all_inlined std::ostream & print (std::ostream &o) const
giv_all_inlined std::istream & operator>> (std::istream &i, Rationel &n)
giv_all_inlined std::ostream & operator<< (std::ostream &o, const Rationel &n)
giv_all_inlined std::ostream & absOutput (std::ostream &o, const Rationel &n)

Member Typedef Documentation

typedef __mpq_struct Rep
protected
typedef __mpz_struct RawRep
protected

Member Enumeration Documentation

enum reduceFlag
Enumerator:
Reduce 
NoReduce 

Constructor & Destructor Documentation

Rationel ( )

default constructor (0/1).

Rationel ( Integer n)

constructors from a single numerator.

Parameters:
nnumerator, will make fraction n/1
Rationel ( int  n)

constructors from a single numerator.

Parameters:
nnumerator, will make fraction n/1
Rationel ( unsigned int  n)

constructors from a single numerator.

Parameters:
nnumerator, will make fraction n/1
Rationel ( long int  n)

constructors from a single numerator.

Parameters:
nnumerator, will make fraction n/1
Rationel ( long unsigned int  n)

constructors from a single numerator.

Parameters:
nnumerator, will make fraction n/1
Rationel ( Integer n,
Integer d,
enum reduceFlag  red = NoReduce 
)

constructors from a numerator and a denominator.

Parameters:
nnumerator
ddenominator, will produce fraction n/d
reduceFlagby defaut, noting is reduced.
Precondition:
we suppose d!=0. this is not asserted in NDEBUG mode !
Todo:
nonZero() ?
Rationel ( int  n,
int  d,
enum reduceFlag  red = NoReduce 
)

constructors from a numerator and a denominator.

Parameters:
nnumerator
ddenominator, will produce fraction n/d
reduceFlagby defaut, noting is reduced.
Precondition:
we suppose d!=0. this is not asserted in NDEBUG mode !
Todo:
nonZero() ?
Rationel ( unsigned int  n,
int  d,
enum reduceFlag  red = NoReduce 
)

constructors from a numerator and a denominator.

Parameters:
nnumerator
ddenominator, will produce fraction n/d
reduceFlagby defaut, noting is reduced.
Precondition:
we suppose d!=0. this is not asserted in NDEBUG mode !
Todo:
nonZero() ?
Rationel ( long int  n,
int  d,
enum reduceFlag  red = NoReduce 
)

constructors from a numerator and a denominator.

Parameters:
nnumerator
ddenominator, will produce fraction n/d
reduceFlagby defaut, noting is reduced.
Precondition:
we suppose d!=0. this is not asserted in NDEBUG mode !
Todo:
nonZero() ?
Rationel ( long unsigned int  n,
int  d,
enum reduceFlag  red = NoReduce 
)

constructors from a numerator and a denominator.

Parameters:
nnumerator
ddenominator, will produce fraction n/d
reduceFlagby defaut, noting is reduced.
Precondition:
we suppose d!=0. this is not asserted in NDEBUG mode !
Todo:
nonZero() ?
Rationel ( int  n,
unsigned int  d,
enum reduceFlag  red = NoReduce 
)

constructors from a numerator and a denominator.

Parameters:
nnumerator
ddenominator, will produce fraction n/d
reduceFlagby defaut, noting is reduced.
Precondition:
we suppose d!=0. this is not asserted in NDEBUG mode !
Todo:
nonZero() ?
Rationel ( int  n,
long int  d,
enum reduceFlag  red = NoReduce 
)

constructors from a numerator and a denominator.

Parameters:
nnumerator
ddenominator, will produce fraction n/d
reduceFlagby defaut, noting is reduced.
Precondition:
we suppose d!=0. this is not asserted in NDEBUG mode !
Todo:
nonZero() ?
Rationel ( int  n,
long unsigned int  d,
enum reduceFlag  red = NoReduce 
)

constructors from a numerator and a denominator.

Parameters:
nnumerator
ddenominator, will produce fraction n/d
reduceFlagby defaut, noting is reduced.
Precondition:
we suppose d!=0. this is not asserted in NDEBUG mode !
Todo:
nonZero() ?
Rationel ( unsigned int  n,
unsigned int  d,
enum reduceFlag  red = NoReduce 
)

constructors from a numerator and a denominator.

Parameters:
nnumerator
ddenominator, will produce fraction n/d
reduceFlagby defaut, noting is reduced.
Precondition:
we suppose d!=0. this is not asserted in NDEBUG mode !
Todo:
nonZero() ?
Rationel ( unsigned int  n,
long int  d,
enum reduceFlag  red = NoReduce 
)

constructors from a numerator and a denominator.

Parameters:
nnumerator
ddenominator, will produce fraction n/d
reduceFlagby defaut, noting is reduced.
Precondition:
we suppose d!=0. this is not asserted in NDEBUG mode !
Todo:
nonZero() ?
Rationel ( unsigned int  n,
long unsigned int  d,
enum reduceFlag  red = NoReduce 
)

constructors from a numerator and a denominator.

Parameters:
nnumerator
ddenominator, will produce fraction n/d
reduceFlagby defaut, noting is reduced.
Precondition:
we suppose d!=0. this is not asserted in NDEBUG mode !
Todo:
nonZero() ?
Rationel ( long unsigned int  n,
unsigned int  d,
enum reduceFlag  red = NoReduce 
)

constructors from a numerator and a denominator.

Parameters:
nnumerator
ddenominator, will produce fraction n/d
reduceFlagby defaut, noting is reduced.
Precondition:
we suppose d!=0. this is not asserted in NDEBUG mode !
Todo:
nonZero() ?
Rationel ( long int  n,
unsigned int  d,
enum reduceFlag  red = NoReduce 
)

constructors from a numerator and a denominator.

Parameters:
nnumerator
ddenominator, will produce fraction n/d
reduceFlagby defaut, noting is reduced.
Precondition:
we suppose d!=0. this is not asserted in NDEBUG mode !
Todo:
nonZero() ?
Rationel ( long int  n,
long int  d,
enum reduceFlag  red = NoReduce 
)

constructors from a numerator and a denominator.

Parameters:
nnumerator
ddenominator, will produce fraction n/d
reduceFlagby defaut, noting is reduced.
Precondition:
we suppose d!=0. this is not asserted in NDEBUG mode !
Todo:
nonZero() ?
Rationel ( long unsigned int  n,
long int  d,
enum reduceFlag  red = NoReduce 
)

constructors from a numerator and a denominator.

Parameters:
nnumerator
ddenominator, will produce fraction n/d
reduceFlagby defaut, noting is reduced.
Precondition:
we suppose d!=0. this is not asserted in NDEBUG mode !
Todo:
nonZero() ?
Rationel ( long int  n,
long unsigned int  d,
enum reduceFlag  red = NoReduce 
)

constructors from a numerator and a denominator.

Parameters:
nnumerator
ddenominator, will produce fraction n/d
reduceFlagby defaut, noting is reduced.
Precondition:
we suppose d!=0. this is not asserted in NDEBUG mode !
Todo:
nonZero() ?
Rationel ( long unsigned int  n,
long unsigned int  d,
enum reduceFlag  red = NoReduce 
)

constructors from a numerator and a denominator.

Parameters:
nnumerator
ddenominator, will produce fraction n/d
reduceFlagby defaut, noting is reduced.
Precondition:
we suppose d!=0. this is not asserted in NDEBUG mode !
Todo:
nonZero() ?
Rationel ( Integer n,
d,
enum reduceFlag  red = NoReduce 
)
Rationel ( n,
Integer d,
enum reduceFlag  red = NoReduce 
)
Rationel ( n,
d,
enum reduceFlag  red = NoReduce 
)
Rationel ( T &  n,
U &  d,
enum reduceFlag  red = NoReduce 
)
Rationel ( Rationel n,
enum reduceFlag  red = NoReduce 
)

constructors from another Rationel

Parameters:
fthe Rationel to be represented
reduceFlaga flag to start reduction or not.
Todo:
Initialise Rationels from mpq_f and mpfr types.
Rationel ( float  f,
enum reduceFlag  red = NoReduce 
)

constructors from another Rationel

Parameters:
fthe Rationel to be represented
reduceFlaga flag to start reduction or not.
Todo:
Initialise Rationels from mpq_f and mpfr types.
Rationel ( double  f,
enum reduceFlag  red = NoReduce 
)

constructors from another Rationel

Parameters:
fthe Rationel to be represented
reduceFlaga flag to start reduction or not.
Todo:
Initialise Rationels from mpq_f and mpfr types.
Rationel ( long double  f,
enum reduceFlag  red = NoReduce 
)

constructors from another Rationel

Parameters:
fthe Rationel to be represented
reduceFlaga flag to start reduction or not.
Todo:
Initialise Rationels from mpq_f and mpfr types.
~Rationel ( )
inline

Destructor.

Clearing the mpq representation.


Member Function Documentation

int privSign ( ) const
protected
const Rep* get_rep ( ) const
inlineprotected
Rationel & addin ( Rationel res,
const Rationel n 
)
static
Rationel & addin ( Rationel res,
const Integer n 
)
static
static giv_all_inlined Rationel& negin ( Rationel res)
inlinestatic
giv_all_inlined Rationel& negin ( )
inline
operator std::string ( ) const
std::ostream & print ( std::ostream &  o) const
Integer getDenom ( ) const

Gets the denominator of a Rationel.

Returns:
the Integer denominator.
Integer getNumer ( ) const

Gets the numerator of a Rationel.

Returns:
the Integer numerator .
mpq_ptr get_mpq ( )

Retrieve the GMP representation of a Rationel.

Returns:
a pointer to this representation.
mpq_srcptr get_mpq_const ( ) const
mpz_ptr get_mpq_den ( ) const

Retrieve the GMP representation of the denominator of a Rationel.

Returns:
a pointer to this denominator (integer).
mpz_ptr get_mpq_num ( ) const

Retrieve the GMP representation of the numerator of a Rationel.

Returns:
a pointer to this numerator (integer).
Rationel & reduce ( )

Reduces (inplace) a fraction to a canonical representation.

Returns:
a reference to self.
Rationel & reduce ( Rationel r)
static

Reduces a fraction to a canonical representation.

Parameters:
ra Rationel
Returns:
a reference to the reduced r.
static int isZero ( const Rationel n)
inlinestatic
giv_all_inlined int isZero ( )
inline
giv_all_inlined Rationel& logcpy ( const Rationel n)
inline
giv_all_inlined Rationel& operator= ( const Rationel n)
inline
giv_all_inlined Rationel& operator= ( const Integer n)
inline
static giv_all_inlined void setInteger ( Rationel f,
const Integer n 
)
inlinestatic

Friends And Related Function Documentation

giv_all_inlined Rationel abs ( const Rationel n)
friend
giv_all_inlined std::istream& operator>> ( std::istream &  i,
Rationel n 
)
friend
giv_all_inlined std::ostream& operator<< ( std::ostream &  o,
const Rationel n 
)
friend
giv_all_inlined std::ostream& absOutput ( std::ostream &  o,
const Rationel n 
)
friend

Field Documentation

Rep gmp_rep
protected
RawRep* num
protected
RawRep* den
protected
reduceFlag flags
staticprotected

flag that indicates reduction is done or not after an operation.

By default, this is Reduce (as in GMP).


The documentation for this class was generated from the following files: