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 <factory/cf_gmp.h>
28 #include "gmpext.h"
29 
30 #ifdef HAVE_OMALLOC
31 #ifndef OM_NDEBUG
32 #define OM_NDEBUG
33 #endif
34 # include <omalloc/omalloc.h>
35 #endif
36 
37 /**
38  * factory's class for integers
39  *
40  * an integer is represented as an mpz_t thempi
41  *
42  * @sa InternalRational
43 **/
45 {
46 private:
47  mpz_t thempi;
48 
49  // auxilliary methods
50  inline InternalCF * normalizeMyself ();
51  inline InternalCF * uiNormalizeMyself ();
52 
53  static inline InternalCF * normalizeMPI ( mpz_ptr );
54  static inline InternalCF * uiNormalizeMPI ( mpz_ptr );
55 
56  static inline mpz_ptr MPI ( const InternalCF * const c );
57 #ifdef HAVE_OMALLOC
58  static const omBin InternalInteger_bin;
59 #endif
60 public:
61 #ifdef HAVE_OMALLOC
62  void* operator new(size_t)
63  {
64  void* addr;
65  omTypeAllocBin(void*, addr, InternalInteger_bin);
66  return addr;
67  }
68  void operator delete(void* addr, size_t)
69  {
70  omFreeBin(addr, InternalInteger_bin);
71  }
72 #endif
73 
76  {
77  ASSERT( 0, "ups there is something wrong in your code" );
78  }
79  InternalInteger( const int i );
80  InternalInteger( const long i );
81  InternalInteger( const char * str, const int base=10 );
82  InternalInteger( const mpz_ptr );
84  InternalCF* deepCopyObject() const;
85  const char * classname() const { return "InternalInteger"; }
86 #ifndef NOSTREAMIO
87  void print( OSTREAM&, char* );
88 #endif /* NOSTREAMIO */
90  InternalCF* genOne();
91 
92  bool is_imm() const;
93 
94  int levelcoeff() const { return IntegerDomain; }
95  InternalCF* neg();
96 
97  int comparesame( InternalCF* );
98 
108 
109  int comparecoeff( InternalCF* );
110 
112  InternalCF* subcoeff( InternalCF*, bool );
114  InternalCF* dividecoeff( InternalCF*, bool );
115  InternalCF* modulocoeff( InternalCF*, bool );
116  InternalCF* divcoeff( InternalCF*, bool );
117  InternalCF* modcoeff( InternalCF*, bool );
118  void divremcoeff( InternalCF*, InternalCF*&, InternalCF*&, bool );
119  bool divremcoefft( InternalCF*, InternalCF*&, InternalCF*&, bool );
120 
121  InternalCF * bgcdsame ( const InternalCF * const ) const;
122  InternalCF * bgcdcoeff ( const InternalCF * const );
123 
126 
127  long intval() const;
128 
129  int intmod( int p ) const;
130 
131  int sign() const;
132 
133  InternalCF* sqrt();
134 
135  int ilog2();
136 
137  friend class InternalRational;
138  friend void gmp_numerator ( const CanonicalForm & f, mpz_ptr result);
139  friend void gmp_denominator ( const CanonicalForm & f, mpz_ptr result );
140  friend void getmpi ( InternalCF * value, mpz_t mpi);
141 };
142 
143 /**
144  *
145  * normalizeMyself(), uiNormalizeMyself() - normalize CO.
146  *
147  * If CO fits into an immediate integer, delete CO and return the
148  * immediate. Otherwise, return a pointer to CO.
149  *
150  * Note: We do not mind reference counting at this point! CO is
151  * deleted unconditionally!
152  *
153 **/
154 inline InternalCF *
156 {
157  ASSERT( getRefCount() == 1, "internal error: must not delete CO" );
158 
159  if ( mpz_is_imm( thempi ) ) {
160  InternalCF * result = int2imm( mpz_get_si( thempi ) );
161  delete this;
162  return result;
163  } else
164  return this;
165 }
166 
167 /**
168  * `uiNormalizeMyself()' is the same as `normalizeMyself()'
169  * except that CO is expected to be non-negative. In this case,
170  * we may use `mpz_get_ui()' to convert the underlying mpi into
171  * an immediate which is slightly faster than the signed variant.
172  *
173  * Note: We do not mind reference counting at this point! CO is
174  * deleted unconditionally!
175 **/
176 inline InternalCF *
178 {
179  ASSERT( getRefCount() == 1, "internal error: must not delete CO" );
180 
181  if ( mpz_is_imm( thempi ) ) {
182  InternalCF * result = int2imm( mpz_get_ui( thempi ) );
183  delete this;
184  return result;
185  } else
186  return this;
187 }
188 
189 /**
190  *
191  * normalizeMPI(), uiNormalizeMPI() - normalize a mpi.
192  *
193  * If `aMpi' fits into an immediate integer, clear `aMpi' and
194  * return the immediate. Otherwise, return a new
195  * `InternalInteger' with `aMpi' as underlying mpi.
196  *
197 **/
198 inline InternalCF *
200 {
201  if ( mpz_is_imm( aMpi ) ) {
202  InternalCF * result = int2imm( mpz_get_si( aMpi ) );
203  mpz_clear( aMpi );
204  return result;
205  } else
206  return new InternalInteger( aMpi );
207 }
208 
209 /**
210  * `uiNormalizeMPI()' is the same as `normalizeMPI()' except that
211  * `aMpi' is expected to be non-begative. In this case, we may
212  * use `mpz_get_ui()' to convert `aMpi' into an immediate which
213  * is slightly faster than the signed variant.
214 **/
215 inline InternalCF *
217 {
218  if ( mpz_is_imm( aMpi ) ) {
219  InternalCF * result = int2imm( mpz_get_ui( aMpi ) );
220  mpz_clear( aMpi );
221  return result;
222  } else
223  return new InternalInteger( aMpi );
224 }
225 
226 /**
227  *
228  * MPI() - return underlying mpz_t of `c'.
229  *
230  * `c' is expected to be an `InternalInteger *'. `c's underlying
231  * mpz_t is returned.
232  *
233 **/
234 inline mpz_ptr
235 InternalInteger::MPI ( const InternalCF * const c )
236 {
237  return (((InternalInteger*)c)->thempi);
238 }
239 
240 #endif /* ! INCL_INT_INT_H */
int comparecoeff(InternalCF *)
Definition: int_int.cc:225
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
bool is_imm() const
Definition: int_int.cc:68
InternalCF * bgcdcoeff(const InternalCF *const )
Definition: int_int.cc:404
InternalInteger(const InternalCF &)
Definition: int_int.h:75
InternalCF * neg()
InternalCF * InternalInteger::neg ()
Definition: int_int.cc:93
static InternalCF * uiNormalizeMPI(mpz_ptr)
`uiNormalizeMPI()&#39; is the same as `normalizeMPI()&#39; except that `aMpi&#39; is expected to be non-begative...
Definition: int_int.h:216
mpz_t thempi
Definition: int_int.h:47
InternalCF * int2imm(long i)
Definition: imm.h:71
return P p
Definition: myNF.cc:203
f
Definition: cfModGcd.cc:4022
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&#39;s main class
Definition: canonicalform.h:75
assertions for Factory
int levelcoeff() const
Definition: int_int.h:94
InternalCF * bgcdsame(const InternalCF *const ) const
Definition: int_int.cc:375
#define omTypeAllocBin(type, addr, bin)
Definition: omAllocDecl.h:203
InternalCF * bextgcdsame(InternalCF *, CanonicalForm &, CanonicalForm &)
Definition: int_int.cc:436
void print(OSTREAM &, char *)
Definition: int_int.cc:53
InternalCF * normalizeMyself()
normalizeMyself(), uiNormalizeMyself() - normalize CO.
Definition: int_int.h:155
int sign() const
int InternalInteger::sign () const
Definition: int_int.cc:547
int comparesame(InternalCF *)
Definition: int_int.cc:215
virtual class for internal CanonicalForm&#39;s
Definition: int_cf.h:39
friend void gmp_denominator(const CanonicalForm &f, mpz_ptr result)
Definition: singext.cc:40
#define IntegerDomain
Definition: cf_defs.h:25
InternalCF * bextgcdcoeff(InternalCF *, CanonicalForm &, CanonicalForm &)
Definition: int_int.cc:491
InternalCF * deepCopyObject() const
Definition: int_int.cc:45
InternalCF * modulocoeff(InternalCF *, bool)
Definition: int_intdiv.cc:212
InternalCF * divsame(InternalCF *)
Definition: int_intdiv.cc:125
InternalCF * subsame(InternalCF *)
Definition: int_int.cc:143
InternalCF * genZero()
Definition: int_int.cc:73
bool divremsamet(InternalCF *, InternalCF *&, InternalCF *&)
Definition: int_intdiv.cc:364
int i
Definition: cfEzgcd.cc:123
InternalCF * addcoeff(InternalCF *)
Definition: int_int.cc:232
InternalCF * subcoeff(InternalCF *, bool)
Definition: int_int.cc:271
#define OSTREAM
Definition: int_int.h:17
static mpz_ptr MPI(const InternalCF *const c)
MPI() - return underlying mpz_t of `c&#39;.
Definition: int_int.h:235
friend void getmpi(InternalCF *value, mpz_t mpi)
Definition: cf_factory.cc:255
InternalCF * sqrt()
InternalCF * InternalInteger::sqrt ()
Definition: int_int.cc:556
InternalCF * mulsame(InternalCF *)
Definition: int_int.cc:174
InternalCF * modsame(InternalCF *)
Definition: int_intdiv.cc:253
InternalCF * modulosame(InternalCF *)
Definition: int_intdiv.cc:186
long intval() const
Definition: int_int.cc:533
InternalCF * dividesame(InternalCF *)
Definition: int_intdiv.cc:28
utility functions for gmp
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:112
Factory&#39;s internal CanonicalForm&#39;s.
#define ASSERT(expression, message)
Definition: cf_assert.h:99
static InternalCF * normalizeMPI(mpz_ptr)
normalizeMPI(), uiNormalizeMPI() - normalize a mpi.
Definition: int_int.h:199
InternalCF * mulcoeff(InternalCF *)
Definition: int_int.cc:326
int ilog2()
int InternalInteger::ilog2 ()
Definition: int_int.cc:576
#define omFreeBin(addr, bin)
Definition: omAllocDecl.h:259
bool mpz_is_imm(const mpz_t mpi)
Definition: gmpext.h:20
factory&#39;s class for integers
Definition: int_int.h:44
InternalCF * uiNormalizeMyself()
`uiNormalizeMyself()&#39; is the same as `normalizeMyself()&#39; except that CO is expected to be non-negativ...
Definition: int_int.h:177
static const omBin InternalInteger_bin
Definition: int_int.h:58
int intmod(int p) const
Definition: int_int.cc:538
InternalCF * genOne()
Definition: int_int.cc:81
factory&#39;s class for rationals
Definition: int_rat.h:39
return result
Definition: facAbsBiFact.cc:76
const char * classname() const
Definition: int_int.h:85
int getRefCount()
Definition: int_cf.h:47