My Project  UNKNOWN_GIT_VERSION
int_int.h
Go to the documentation of this file.
1 /* emacs edit mode for this file is -*- C++ -*- */
2 
3 #ifndef INCL_INT_INT_H
4 #define INCL_INT_INT_H
5 
6 /**
7  * @file int_int.h
8  *
9  * Factory's internal integers
10 **/
11 
12 // #include "config.h"
13 
14 #ifndef NOSTREAMIO
15 #ifdef HAVE_IOSTREAM
16 #include <iostream>
17 #define OSTREAM std::ostream
18 #elif defined(HAVE_IOSTREAM_H)
19 #include <iostream.h>
20 #define OSTREAM ostream
21 #endif
22 #endif /* NOSTREAMIO */
23 
24 #include "cf_assert.h"
25 
26 #include "int_cf.h"
27 #include "gmpext.h"
28 
29 #ifdef HAVE_OMALLOC
30 # include "omalloc/omalloc.h"
31 #endif
32 
33 /**
34  * factory's class for integers
35  *
36  * an integer is represented as an mpz_t thempi
37  *
38  * @sa InternalRational
39 **/
41 {
42 private:
43  mpz_t thempi;
44 
45  // auxilliary methods
46  inline InternalCF * normalizeMyself ();
47  inline InternalCF * uiNormalizeMyself ();
48 
49  static inline InternalCF * normalizeMPI ( mpz_ptr );
50  static inline InternalCF * uiNormalizeMPI ( mpz_ptr );
51 
52  static inline mpz_ptr MPI ( const InternalCF * const c );
53 #ifdef HAVE_OMALLOC
54  static const omBin InternalInteger_bin;
55 #endif
56 public:
57 #ifdef HAVE_OMALLOC
58  void* operator new(size_t)
59  {
60  void* addr;
61  omTypeAllocBin(void*, addr, InternalInteger_bin);
62  return addr;
63  }
64  void operator delete(void* addr, size_t)
65  {
67  }
68 #endif
69 
70  InternalInteger() { mpz_init( thempi ); }
72  {
73  ASSERT( 0, "ups there is something wrong in your code" );
74  }
75  InternalInteger( const int i ) { mpz_init_set_si( thempi, (long)i );}
76  InternalInteger( const long i ) { mpz_init_set_si( thempi, i );}
77  InternalInteger( const char * str, const int base=10 )
78  { mpz_init_set_str( thempi, str, base ); }
79  InternalInteger( const mpz_ptr mpi) {thempi[0]=*mpi;}
80  ~InternalInteger() { mpz_clear( thempi ); }
81  InternalCF* deepCopyObject() const;
82  const char * classname() const { return "InternalInteger"; }
83 #ifndef NOSTREAMIO
84  void print( OSTREAM&, char* );
85 #endif /* NOSTREAMIO */
87  InternalCF* genOne();
88 
89  bool is_imm() const;
90 
91  int levelcoeff() const { return IntegerDomain; }
92  InternalCF* neg();
93 
94  int comparesame( InternalCF* );
95 
105 
106  int comparecoeff( InternalCF* );
107 
109  InternalCF* subcoeff( InternalCF*, bool );
111  InternalCF* dividecoeff( InternalCF*, bool );
112  InternalCF* modulocoeff( InternalCF*, bool );
113  InternalCF* divcoeff( InternalCF*, bool );
114  InternalCF* modcoeff( InternalCF*, bool );
115  void divremcoeff( InternalCF*, InternalCF*&, InternalCF*&, bool );
116  bool divremcoefft( InternalCF*, InternalCF*&, InternalCF*&, bool );
117 
118  InternalCF * bgcdsame ( const InternalCF * const ) const;
119  InternalCF * bgcdcoeff ( const InternalCF * const );
120 
123 
124  long intval() const;
125 
126  int intmod( int p ) const;
127 
128  int sign() const;
129 
130  InternalCF* sqrt();
131 
132  int ilog2();
133 
134  friend class InternalRational;
135  friend void gmp_numerator ( const CanonicalForm & f, mpz_ptr result);
136  friend void gmp_denominator ( const CanonicalForm & f, mpz_ptr result );
137  friend void getmpi ( InternalCF * value, mpz_t mpi);
138 };
139 
140 /**
141  *
142  * normalizeMyself(), uiNormalizeMyself() - normalize CO.
143  *
144  * If CO fits into an immediate integer, delete CO and return the
145  * immediate. Otherwise, return a pointer to CO.
146  *
147  * Note: We do not mind reference counting at this point! CO is
148  * deleted unconditionally!
149  *
150 **/
151 inline InternalCF *
153 {
154  ASSERT( getRefCount() == 1, "internal error: must not delete CO" );
155 
156  if ( mpz_is_imm( thempi ) ) {
157  InternalCF * result = int2imm( mpz_get_si( thempi ) );
158  delete this;
159  return result;
160  } else
161  return this;
162 }
163 
164 /**
165  * `uiNormalizeMyself()' is the same as `normalizeMyself()'
166  * except that CO is expected to be non-negative. In this case,
167  * we may use `mpz_get_ui()' to convert the underlying mpi into
168  * an immediate which is slightly faster than the signed variant.
169  *
170  * Note: We do not mind reference counting at this point! CO is
171  * deleted unconditionally!
172 **/
173 inline InternalCF *
175 {
176  ASSERT( getRefCount() == 1, "internal error: must not delete CO" );
177 
178  if ( mpz_is_imm( thempi ) ) {
179  InternalCF * result = int2imm( mpz_get_ui( thempi ) );
180  delete this;
181  return result;
182  } else
183  return this;
184 }
185 
186 /**
187  *
188  * normalizeMPI(), uiNormalizeMPI() - normalize a mpi.
189  *
190  * If `aMpi' fits into an immediate integer, clear `aMpi' and
191  * return the immediate. Otherwise, return a new
192  * `InternalInteger' with `aMpi' as underlying mpi.
193  *
194 **/
195 inline InternalCF *
197 {
198  if ( mpz_is_imm( aMpi ) ) {
199  InternalCF * result = int2imm( mpz_get_si( aMpi ) );
200  mpz_clear( aMpi );
201  return result;
202  } else
203  return new InternalInteger( aMpi );
204 }
205 
206 /**
207  * `uiNormalizeMPI()' is the same as `normalizeMPI()' except that
208  * `aMpi' is expected to be non-begative. In this case, we may
209  * use `mpz_get_ui()' to convert `aMpi' into an immediate which
210  * is slightly faster than the signed variant.
211 **/
212 inline InternalCF *
214 {
215  if ( mpz_is_imm( aMpi ) ) {
216  InternalCF * result = int2imm( mpz_get_ui( aMpi ) );
217  mpz_clear( aMpi );
218  return result;
219  } else
220  return new InternalInteger( aMpi );
221 }
222 
223 /**
224  *
225  * MPI() - return underlying mpz_t of `c'.
226  *
227  * `c' is expected to be an `InternalInteger *'. `c's underlying
228  * mpz_t is returned.
229  *
230 **/
231 inline mpz_ptr
232 InternalInteger::MPI ( const InternalCF * const c )
233 {
234  return (((InternalInteger*)c)->thempi);
235 }
236 
237 #endif /* ! INCL_INT_INT_H */
int comparecoeff(InternalCF *)
Definition: int_int.cc:198
InternalCF * divcoeff(InternalCF *, bool)
Definition: int_intdiv.cc:151
omBin_t * omBin
Definition: omStructs.h:12
void divremsame(InternalCF *, InternalCF *&, InternalCF *&)
Definition: int_intdiv.cc:271
InternalInteger(const InternalCF &)
Definition: int_int.h:71
InternalCF * neg()
InternalCF * InternalInteger::neg ()
Definition: int_int.cc:66
static InternalCF * uiNormalizeMPI(mpz_ptr)
‘uiNormalizeMPI()’ is the same as ‘normalizeMPI()’ except that ‘aMpi’ is expected to be non-begative.
Definition: int_int.h:213
mpz_t thempi
Definition: int_int.h:43
static InternalCF * int2imm(long i)
Definition: imm.h:75
InternalCF * bgcdcoeff(const InternalCF *const)
Definition: int_int.cc:377
InternalCF * dividecoeff(InternalCF *, bool)
Definition: int_intdiv.cc:69
friend void gmp_numerator(const CanonicalForm &f, mpz_ptr result)
Definition: singext.cc:20
char N base
Definition: ValueTraits.h:144
factory's main class
Definition: canonicalform.h:77
assertions for Factory
#define omTypeAllocBin(type, addr, bin)
Definition: omAllocDecl.h:203
InternalCF * bextgcdsame(InternalCF *, CanonicalForm &, CanonicalForm &)
Definition: int_int.cc:409
void print(OSTREAM &, char *)
Definition: int_int.cc:26
InternalCF * normalizeMyself()
normalizeMyself(), uiNormalizeMyself() - normalize CO.
Definition: int_int.h:152
int comparesame(InternalCF *)
Definition: int_int.cc:188
virtual class for internal CanonicalForm's
Definition: int_cf.h:41
friend void gmp_denominator(const CanonicalForm &f, mpz_ptr result)
Definition: singext.cc:40
#define IntegerDomain
Definition: cf_defs.h:25
InternalInteger(const char *str, const int base=10)
Definition: int_int.h:77
InternalCF * bextgcdcoeff(InternalCF *, CanonicalForm &, CanonicalForm &)
Definition: int_int.cc:464
InternalCF * modulocoeff(InternalCF *, bool)
Definition: int_intdiv.cc:212
InternalCF * divsame(InternalCF *)
Definition: int_intdiv.cc:125
InternalCF * subsame(InternalCF *)
Definition: int_int.cc:116
long intval() const
Definition: int_int.cc:506
InternalCF * genZero()
Definition: int_int.cc:46
bool divremsamet(InternalCF *, InternalCF *&, InternalCF *&)
Definition: int_intdiv.cc:364
FILE * f
Definition: checklibs.c:9
int i
Definition: cfEzgcd.cc:125
InternalCF * addcoeff(InternalCF *)
Definition: int_int.cc:205
InternalCF * subcoeff(InternalCF *, bool)
Definition: int_int.cc:244
#define OSTREAM
Definition: int_int.h:17
static mpz_ptr MPI(const InternalCF *const c)
MPI() - return underlying mpz_t of ‘c’.
Definition: int_int.h:232
int intmod(int p) const
Definition: int_int.cc:511
friend void getmpi(InternalCF *value, mpz_t mpi)
Definition: cf_factory.cc:260
InternalCF * sqrt()
InternalCF * InternalInteger::sqrt ()
Definition: int_int.cc:529
InternalCF * mulsame(InternalCF *)
Definition: int_int.cc:147
InternalCF * modsame(InternalCF *)
Definition: int_intdiv.cc:253
InternalCF * modulosame(InternalCF *)
Definition: int_intdiv.cc:186
InternalInteger(const mpz_ptr mpi)
Definition: int_int.h:79
~InternalInteger()
Definition: int_int.h:80
InternalCF * dividesame(InternalCF *)
Definition: int_intdiv.cc:28
utility functions for gmp
InternalCF * deepCopyObject() const
Definition: int_int.cc:18
InternalInteger(const long i)
Definition: int_int.h:76
InternalInteger(const int i)
Definition: int_int.h:75
InternalCF * modcoeff(InternalCF *, bool)
Definition: int_intdiv.cc:262
bool divremcoefft(InternalCF *, InternalCF *&, InternalCF *&, bool)
Definition: int_intdiv.cc:374
void divremcoeff(InternalCF *, InternalCF *&, InternalCF *&, bool)
Definition: int_intdiv.cc:308
InternalCF * addsame(InternalCF *)
Definition: int_int.cc:85
Factory's internal CanonicalForm's.
InternalCF * bgcdsame(const InternalCF *const) const
Definition: int_int.cc:348
#define ASSERT(expression, message)
Definition: cf_assert.h:99
static InternalCF * normalizeMPI(mpz_ptr)
normalizeMPI(), uiNormalizeMPI() - normalize a mpi.
Definition: int_int.h:196
int sign() const
int InternalInteger::sign () const
Definition: int_int.cc:520
InternalCF * mulcoeff(InternalCF *)
Definition: int_int.cc:299
int p
Definition: cfModGcd.cc:4019
int levelcoeff() const
Definition: int_int.h:91
int ilog2()
int InternalInteger::ilog2 ()
Definition: int_int.cc:549
#define omFreeBin(addr, bin)
Definition: omAllocDecl.h:259
bool mpz_is_imm(const mpz_t mpi)
Definition: gmpext.h:19
factory's class for integers
Definition: int_int.h:40
InternalCF * uiNormalizeMyself()
‘uiNormalizeMyself()’ is the same as ‘normalizeMyself()’ except that CO is expected to be non-negativ...
Definition: int_int.h:174
static const omBin InternalInteger_bin
Definition: int_int.h:54
InternalCF * genOne()
Definition: int_int.cc:54
bool is_imm() const
Definition: int_int.cc:41
factory's class for rationals
Definition: int_rat.h:38
return result
Definition: facAbsBiFact.cc:76
const char * classname() const
Definition: int_int.h:82
int getRefCount()
Definition: int_cf.h:51