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). More...
 
 ~Rationel ()
 Destructor. More...
 
giv_all_inlined Rationelnegin ()
 
giv_all_inlined operator std::string () const
 
giv_all_inlined Integer getDenom () const
 Gets the denominator of a Rationel. More...
 
giv_all_inlined Integer getNumer () const
 Gets the numerator of a Rationel. More...
 
giv_all_inlined mpq_ptr get_mpq ()
 Retrieve the GMP representation of a Rationel. More...
 
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. More...
 
giv_all_inlined mpz_ptr get_mpq_num () const
 Retrieve the GMP representation of the numerator of a Rationel. More...
 
giv_all_inlined Rationelreduce ()
 Reduces (inplace) a fraction to a canonical representation. More...
 
giv_all_inlined int32_t isZero ()
 
giv_all_inlined Rationellogcpy (const Rationel &n)
 
giv_all_inlined Rationeloperator= (const Rationel &n)
 
giv_all_inlined Rationeloperator= (const Integer &n)
 
template<class T >
 Rationel (Integer &n, T d, enum reduceFlag red)
 
template<class T >
 Rationel (T n, Integer &d, enum reduceFlag red)
 
template<class T , class U >
 Rationel (T n, U d, enum reduceFlag red)
 
template<class T , class U >
 Rationel (T &n, U &d, enum reduceFlag red)
 
giv_all_inlined Rationel (Integer &n)
 constructors from a single numerator. More...
 
giv_all_inlined Rationel (int32_t n)
 constructors from a single numerator. More...
 
giv_all_inlined Rationel (uint32_t n)
 constructors from a single numerator. More...
 
giv_all_inlined Rationel (int64_t n)
 constructors from a single numerator. More...
 
giv_all_inlined Rationel (uint64_t n)
 constructors from a single numerator. More...
 
giv_all_inlined Rationel (Integer &n, Integer &d, enum reduceFlag=NoReduce)
 constructors from a numerator and a denominator. More...
 
giv_all_inlined Rationel (int32_t n, int32_t d, enum reduceFlag=NoReduce)
 constructors from a numerator and a denominator. More...
 
giv_all_inlined Rationel (uint32_t n, int32_t d, enum reduceFlag=NoReduce)
 constructors from a numerator and a denominator. More...
 
giv_all_inlined Rationel (int64_t n, int32_t d, enum reduceFlag=NoReduce)
 constructors from a numerator and a denominator. More...
 
giv_all_inlined Rationel (uint64_t n, int32_t d, enum reduceFlag=NoReduce)
 constructors from a numerator and a denominator. More...
 
giv_all_inlined Rationel (int32_t n, uint32_t d, enum reduceFlag=NoReduce)
 constructors from a numerator and a denominator. More...
 
giv_all_inlined Rationel (int32_t n, int64_t d, enum reduceFlag=NoReduce)
 constructors from a numerator and a denominator. More...
 
giv_all_inlined Rationel (int32_t n, uint64_t d, enum reduceFlag=NoReduce)
 constructors from a numerator and a denominator. More...
 
giv_all_inlined Rationel (uint32_t n, uint32_t d, enum reduceFlag=NoReduce)
 constructors from a numerator and a denominator. More...
 
giv_all_inlined Rationel (uint32_t n, int64_t d, enum reduceFlag=NoReduce)
 constructors from a numerator and a denominator. More...
 
giv_all_inlined Rationel (uint32_t n, uint64_t d, enum reduceFlag=NoReduce)
 constructors from a numerator and a denominator. More...
 
giv_all_inlined Rationel (uint64_t n, uint32_t d, enum reduceFlag=NoReduce)
 constructors from a numerator and a denominator. More...
 
giv_all_inlined Rationel (int64_t n, uint32_t d, enum reduceFlag=NoReduce)
 constructors from a numerator and a denominator. More...
 
giv_all_inlined Rationel (int64_t n, int64_t d, enum reduceFlag=NoReduce)
 constructors from a numerator and a denominator. More...
 
giv_all_inlined Rationel (uint64_t n, int64_t d, enum reduceFlag=NoReduce)
 constructors from a numerator and a denominator. More...
 
giv_all_inlined Rationel (int64_t n, uint64_t d, enum reduceFlag=NoReduce)
 constructors from a numerator and a denominator. More...
 
giv_all_inlined Rationel (uint64_t n, uint64_t d, enum reduceFlag=NoReduce)
 constructors from a numerator and a denominator. More...
 
template<class T >
giv_all_inlined Rationel (Integer &n, T d, enum reduceFlag=NoReduce)
 constructors from a numerator and a denominator. More...
 
template<class T >
giv_all_inlined Rationel (T n, Integer &d, enum reduceFlag=NoReduce)
 constructors from a numerator and a denominator. More...
 
template<class T , class U >
giv_all_inlined Rationel (T n, U d, enum reduceFlag=NoReduce)
 constructors from a numerator and a denominator. More...
 
template<class T , class U >
giv_all_inlined Rationel (T &n, U &d, enum reduceFlag=NoReduce)
 constructors from a numerator and a denominator. More...
 
giv_all_inlined Rationel (Rationel &f, enum reduceFlag=NoReduce)
 constructors from another Rationel More...
 
giv_all_inlined Rationel (float f, enum reduceFlag=NoReduce)
 constructors from another Rationel More...
 
giv_all_inlined Rationel (double f, enum reduceFlag=NoReduce)
 constructors from another Rationel More...
 
giv_all_inlined Rationel (long double f, enum reduceFlag=NoReduce)
 constructors from another Rationel More...
 

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. More...
 
static int32_t 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

int32_t 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. More...
 

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 ( int32_t  n)

constructors from a single numerator.

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

constructors from a single numerator.

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

constructors from a single numerator.

Parameters
nnumerator, will make fraction n/1
Rationel ( uint64_t  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 ( int32_t  n,
int32_t  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 ( uint32_t  n,
int32_t  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 ( int64_t  n,
int32_t  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 ( uint64_t  n,
int32_t  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 ( int32_t  n,
uint32_t  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 ( int32_t  n,
int64_t  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 ( int32_t  n,
uint64_t  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 ( uint32_t  n,
uint32_t  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 ( uint32_t  n,
int64_t  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 ( uint32_t  n,
uint64_t  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 ( uint64_t  n,
uint32_t  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 ( int64_t  n,
uint32_t  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 ( int64_t  n,
int64_t  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 ( uint64_t  n,
int64_t  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 ( int64_t  n,
uint64_t  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 ( uint64_t  n,
uint64_t  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() ?
giv_all_inlined Rationel ( Integer n,
d,
enum  reduceFlag = 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() ?
giv_all_inlined Rationel ( n,
Integer d,
enum  reduceFlag = 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() ?
giv_all_inlined Rationel ( n,
d,
enum  reduceFlag = 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() ?
giv_all_inlined Rationel ( T &  n,
U &  d,
enum  reduceFlag = 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 ( 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.

Rationel ( Integer n,
d,
enum reduceFlag  red 
)
Rationel ( n,
Integer d,
enum reduceFlag  red 
)
Rationel ( n,
d,
enum reduceFlag  red 
)
Rationel ( T &  n,
U &  d,
enum reduceFlag  red 
)

Member Function Documentation

int32_t 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 int32_t isZero ( const Rationel n)
inlinestatic
giv_all_inlined int32_t 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: