My Project
Loading...
Searching...
No Matches
int_rat.h
Go to the documentation of this file.
1/* emacs edit mode for this file is -*- C++ -*- */
2
3#ifndef INCL_INT_RAT_H
4#define INCL_INT_RAT_H
5
6/**
7 * @file int_rat.h
8 *
9 * Factory's internal rationals
10**/
11// #include "config.h"
12
13#ifndef NOSTREAMIO
14#ifdef HAVE_IOSTREAM
15#include <iostream>
16#define OSTREAM std::ostream
17#elif defined(HAVE_IOSTREAM_H)
18#include <iostream.h>
19#define OSTREAM ostream
20#endif
21#endif /* NOSTREAMIO */
22
23#include "cf_assert.h"
24
25#include "canonicalform.h"
26#include "int_cf.h"
27#include "imm.h"
28
29#ifdef HAVE_FLINT
30#ifdef __cplusplus
31extern "C"
32{
33#endif
34#ifndef __GMP_BITS_PER_MP_LIMB
35#define __GMP_BITS_PER_MP_LIMB GMP_LIMB_BITS
36#endif
37#include <flint/fmpz.h>
38#include <flint/fmpq.h>
39#ifdef __cplusplus
40}
41#endif
42#endif
43
44
45/**
46 * factory's class for rationals
47 *
48 * a rational is represented as two mpz_t's _num, _den
49 *
50 * Note: If you want to compute over Q make sure that SW_RATIONAL is set to 1!
51 *
52 * @sa InternalInteger
53**/
55{
56private:
57 mpz_t _num;
58 mpz_t _den;
60 static mpz_ptr MPQNUM( const InternalCF * const c );
61 static mpz_ptr MPQDEN( const InternalCF * const c );
62 static void normalize( const mpz_ptr, const mpz_ptr, mpz_ptr, mpz_ptr );
63public:
66 {
67 ASSERT( 0, "ups there is something wrong in your code" );
68 }
69 InternalRational( const int i );
70 InternalRational( const int n, const int d );
71 InternalRational( const long i );
72 InternalRational( const long n, const long d );
73 InternalRational( const char * str );
74 InternalRational( const mpz_ptr );
75 InternalRational( const mpz_ptr , const mpz_ptr );
78 const char * classname() const { return "InternalRational"; }
79#ifndef NOSTREAMIO
80 void print( OSTREAM&, char* );
81#endif /* NOSTREAMIO */
84
85 bool is_imm() const;
86 int levelcoeff() const { return RationalDomain; }
87
88 InternalCF* num();
89 InternalCF* den();
90
91 InternalCF* neg();
92
93 int comparesame( InternalCF* );
94
104
105 int comparecoeff( InternalCF* );
106
108 InternalCF* subcoeff( InternalCF*, bool );
112 InternalCF* divcoeff( InternalCF*, bool );
113 InternalCF* modcoeff( InternalCF*, bool );
114 void divremcoeff( InternalCF*, InternalCF*&, InternalCF*&, bool );
115 bool divremcoefft( InternalCF*, InternalCF*&, InternalCF*&, bool );
116
117 InternalCF * bgcdsame ( const InternalCF * const ) const;
118 InternalCF * bgcdcoeff ( const InternalCF * const );
119
122
123 long intval() const;
124
125 int sign() const;
126
128
129 friend class InternalInteger;
130 friend void gmp_numerator ( const CanonicalForm & f, mpz_ptr result );
131 friend void gmp_denominator ( const CanonicalForm & f, mpz_ptr result );
132 friend CanonicalForm make_cf ( const mpz_ptr n, const mpz_ptr d );
133#ifdef HAVE_FLINT
134 friend void convertCF2Fmpq(fmpq_t result, const CanonicalForm& f);
135#endif
136};
137
138inline mpz_ptr InternalRational::MPQNUM( const InternalCF * const c )
139{
140 return (((InternalRational*)c)->_num);
141}
142
143inline mpz_ptr InternalRational::MPQDEN( const InternalCF * const c )
144{
145 return (((InternalRational*)c)->_den);
146}
147
148#endif /* ! INCL_INT_RAT_H */
Header for factory's main class CanonicalForm.
#define OSTREAM
int i
Definition cfEzgcd.cc:132
assertions for Factory
#define ASSERT(expression, message)
Definition cf_assert.h:99
#define RationalDomain
Definition cf_defs.h:20
FILE * f
Definition checklibs.c:9
factory's main class
virtual class for internal CanonicalForm's
Definition int_cf.h:47
InternalCF()
Definition int_cf.h:55
void divremcoeff(InternalCF *, InternalCF *&, InternalCF *&, bool)
Definition int_rat.cc:805
InternalCF * divsame(InternalCF *)
Definition int_rat.cc:473
STATIC_VAR int initialized
Definition int_rat.h:59
InternalCF * bextgcdcoeff(InternalCF *, CanonicalForm &, CanonicalForm &)
Definition int_rat.cc:850
InternalCF * subcoeff(InternalCF *, bool)
Definition int_rat.cc:597
InternalCF * normalize_myself()
reduce InternalRational to lowest terms
Definition int_rat.cc:859
int comparesame(InternalCF *)
comparesame(), comparecoeff() - compare with an InternalRational.
Definition int_rat.cc:516
friend void gmp_denominator(const CanonicalForm &f, mpz_ptr result)
Definition singext.cc:40
friend class InternalInteger
Definition int_rat.h:129
long intval() const
Definition int_rat.cc:897
int levelcoeff() const
Definition int_rat.h:86
InternalCF * modsame(InternalCF *)
Definition int_rat.cc:483
InternalCF * genOne()
Definition int_rat.cc:167
bool is_imm() const
Definition int_rat.cc:154
int sign() const
Definition int_rat.cc:909
InternalCF * addsame(InternalCF *)
Definition int_rat.cc:234
InternalCF * bgcdcoeff(const InternalCF *const)
Definition int_rat.cc:831
InternalCF * num()
Definition int_rat.cc:178
InternalCF * genZero()
Definition int_rat.cc:159
bool divremcoefft(InternalCF *, InternalCF *&, InternalCF *&, bool)
Definition int_rat.cc:812
bool divremsamet(InternalCF *, InternalCF *&, InternalCF *&)
Definition int_rat.cc:496
InternalCF * bextgcdsame(InternalCF *, CanonicalForm &, CanonicalForm &)
Definition int_rat.cc:840
InternalCF * bgcdsame(const InternalCF *const) const
Definition int_rat.cc:822
InternalCF * mulsame(InternalCF *)
Definition int_rat.cc:348
InternalCF * modcoeff(InternalCF *, bool)
Definition int_rat.cc:797
friend CanonicalForm make_cf(const mpz_ptr n, const mpz_ptr d)
InternalCF * deepCopyObject() const
Definition int_rat.cc:131
void divremsame(InternalCF *, InternalCF *&, InternalCF *&)
Definition int_rat.cc:489
InternalCF * divcoeff(InternalCF *, bool)
Definition int_rat.cc:787
InternalCF * dividecoeff(InternalCF *, bool)
Definition int_rat.cc:707
InternalCF * dividesame(InternalCF *)
Definition int_rat.cc:408
friend void convertCF2Fmpq(fmpq_t result, const CanonicalForm &f)
conversion of a factory rationals to fmpq_t
InternalCF * den()
Definition int_rat.cc:196
InternalCF * neg()
InternalCF * InternalRational::neg ()
Definition int_rat.cc:215
InternalCF * addcoeff(InternalCF *)
Definition int_rat.cc:560
friend void gmp_numerator(const CanonicalForm &f, mpz_ptr result)
Definition singext.cc:20
static mpz_ptr MPQDEN(const InternalCF *const c)
Definition int_rat.h:143
InternalCF * modulosame(InternalCF *)
Definition int_rat.cc:478
void print(OSTREAM &, char *)
Definition int_rat.cc:141
const char * classname() const
Definition int_rat.h:78
int comparecoeff(InternalCF *)
comparecoeff() compares the CO=a/b and the integer c using the equivalence a/b < c iff a < c*b.
Definition int_rat.cc:536
InternalRational(const InternalCF &)
Definition int_rat.h:65
InternalCF * subsame(InternalCF *)
Definition int_rat.cc:292
static void normalize(const mpz_ptr, const mpz_ptr, mpz_ptr, mpz_ptr)
static mpz_ptr MPQNUM(const InternalCF *const c)
Definition int_rat.h:138
InternalCF * modulocoeff(InternalCF *, bool)
Definition int_rat.cc:792
InternalCF * mulcoeff(InternalCF *)
Definition int_rat.cc:654
return result
#define STATIC_VAR
Definition globaldefs.h:7
operations on immediates, that is elements of F_p, GF, Z, Q that fit into intrinsic int,...
Factory's internal CanonicalForm's.