My Project
Loading...
Searching...
No Matches
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#ifdef HAVE_FLINT
25#ifdef __cplusplus
26extern "C"
27{
28#endif
29#ifndef __GMP_BITS_PER_MP_LIMB
30#define __GMP_BITS_PER_MP_LIMB GMP_LIMB_BITS
31#endif
32#include <flint/fmpz.h>
33#include <flint/fmpq.h>
34#ifdef __cplusplus
35}
36#endif
37#endif
38
39#include "cf_assert.h"
40
41#include "int_cf.h"
42#include "gmpext.h"
43
44#ifdef HAVE_OMALLOC
45# include "omalloc/omalloc.h"
46#endif
47
48/**
49 * factory's class for integers
50 *
51 * an integer is represented as an mpz_t thempi
52 *
53 * @sa InternalRational
54**/
56{
57private:
58 mpz_t thempi;
59
60 // auxilliary methods
61 inline InternalCF * normalizeMyself ();
62 inline InternalCF * uiNormalizeMyself ();
63
64 static inline InternalCF * normalizeMPI ( mpz_ptr );
65 static inline InternalCF * uiNormalizeMPI ( mpz_ptr );
66
67 static inline mpz_ptr MPI ( const InternalCF * const c );
68#ifdef HAVE_OMALLOC
70#endif
71public:
72#ifdef HAVE_OMALLOC
73 void* operator new(size_t)
74 {
75 void* addr;
77 return addr;
78 }
79 void operator delete(void* addr, size_t)
80 {
82 }
83#endif
84
85 InternalInteger() { mpz_init( thempi ); }
87 {
88 ASSERT( 0, "ups there is something wrong in your code" );
89 }
90 InternalInteger( const int i ) { mpz_init_set_si( thempi, (long)i );}
91 InternalInteger( const long i ) { mpz_init_set_si( thempi, i );}
92 InternalInteger( const char * str, const int base=10 )
93 { mpz_init_set_str( thempi, str, base ); }
94 InternalInteger( const mpz_ptr mpi) {thempi[0]=*mpi;}
95 ~InternalInteger() { mpz_clear( thempi ); }
97 const char * classname() const { return "InternalInteger"; }
98#ifndef NOSTREAMIO
99 void print( OSTREAM&, char* );
100#endif /* NOSTREAMIO */
103
104 bool is_imm() const;
105
106 int levelcoeff() const { return IntegerDomain; }
107 InternalCF* neg();
108
109 int comparesame( InternalCF* );
110
120
121 int comparecoeff( InternalCF* );
122
124 InternalCF* subcoeff( InternalCF*, bool );
128 InternalCF* divcoeff( InternalCF*, bool );
129 InternalCF* modcoeff( InternalCF*, bool );
130 void divremcoeff( InternalCF*, InternalCF*&, InternalCF*&, bool );
131 bool divremcoefft( InternalCF*, InternalCF*&, InternalCF*&, bool );
132
133 InternalCF * bgcdsame ( const InternalCF * const ) const;
134 InternalCF * bgcdcoeff ( const InternalCF * const );
135
138
139 long intval() const;
140
141 int intmod( int p ) const;
142
143 int sign() const;
144
145 InternalCF* sqrt();
146
147 int ilog2();
148
149 friend class InternalRational;
150 friend void gmp_numerator ( const CanonicalForm & f, mpz_ptr result);
151 friend void gmp_denominator ( const CanonicalForm & f, mpz_ptr result );
152 friend void getmpi ( InternalCF * value, mpz_t mpi);
153 #ifdef HAVE_FLINT
154 friend void convertCF2Fmpz(fmpz*, const CanonicalForm&);
155 friend void convertCF2initFmpz (fmpz_t result, const CanonicalForm& f);
156 friend void convertCF2Fmpq(fmpq_t result, const CanonicalForm& f);
157 #endif
158};
159
160/**
161 *
162 * normalizeMyself(), uiNormalizeMyself() - normalize CO.
163 *
164 * If CO fits into an immediate integer, delete CO and return the
165 * immediate. Otherwise, return a pointer to CO.
166 *
167 * Note: We do not mind reference counting at this point! CO is
168 * deleted unconditionally!
169 *
170**/
171inline InternalCF *
173{
174 ASSERT( getRefCount() == 1, "internal error: must not delete CO" );
175
176 if ( mpz_is_imm( thempi ) ) {
177 InternalCF * result = int2imm( mpz_get_si( thempi ) );
178 delete this;
179 return result;
180 } else
181 return this;
182}
183
184/**
185 * `uiNormalizeMyself()' is the same as `normalizeMyself()'
186 * except that CO is expected to be non-negative. In this case,
187 * we may use `mpz_get_ui()' to convert the underlying mpi into
188 * an immediate which is slightly faster than the signed variant.
189 *
190 * Note: We do not mind reference counting at this point! CO is
191 * deleted unconditionally!
192**/
193inline InternalCF *
195{
196 ASSERT( getRefCount() == 1, "internal error: must not delete CO" );
197
198 if ( mpz_is_imm( thempi ) ) {
199 InternalCF * result = int2imm( mpz_get_ui( thempi ) );
200 delete this;
201 return result;
202 } else
203 return this;
204}
205
206/**
207 *
208 * normalizeMPI(), uiNormalizeMPI() - normalize a mpi.
209 *
210 * If `aMpi' fits into an immediate integer, clear `aMpi' and
211 * return the immediate. Otherwise, return a new
212 * `InternalInteger' with `aMpi' as underlying mpi.
213 *
214**/
215inline InternalCF *
217{
218 if ( mpz_is_imm( aMpi ) ) {
219 InternalCF * result = int2imm( mpz_get_si( aMpi ) );
220 mpz_clear( aMpi );
221 return result;
222 } else
223 return new InternalInteger( aMpi );
224}
225
226/**
227 * `uiNormalizeMPI()' is the same as `normalizeMPI()' except that
228 * `aMpi' is expected to be non-begative. In this case, we may
229 * use `mpz_get_ui()' to convert `aMpi' into an immediate which
230 * is slightly faster than the signed variant.
231**/
232inline InternalCF *
234{
235 if ( mpz_is_imm( aMpi ) ) {
236 InternalCF * result = int2imm( mpz_get_ui( aMpi ) );
237 mpz_clear( aMpi );
238 return result;
239 } else
240 return new InternalInteger( aMpi );
241}
242
243/**
244 *
245 * MPI() - return underlying mpz_t of `c'.
246 *
247 * `c' is expected to be an `InternalInteger *'. `c's underlying
248 * mpz_t is returned.
249 *
250**/
251inline mpz_ptr
253{
254 return (((InternalInteger*)c)->thempi);
255}
256
257#endif /* ! INCL_INT_INT_H */
#define OSTREAM
int i
Definition cfEzgcd.cc:132
int p
Definition cfModGcd.cc:4086
assertions for Factory
#define ASSERT(expression, message)
Definition cf_assert.h:99
#define IntegerDomain
Definition cf_defs.h:21
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
int getRefCount()
Definition int_cf.h:51
InternalInteger(const InternalCF &)
Definition int_int.h:86
InternalCF * dividecoeff(InternalCF *, bool)
Definition int_intdiv.cc:69
InternalCF * deepCopyObject() const
Definition int_int.cc:18
InternalCF * normalizeMyself()
normalizeMyself(), uiNormalizeMyself() - normalize CO.
Definition int_int.h:172
InternalCF * modsame(InternalCF *)
static InternalCF * uiNormalizeMPI(mpz_ptr)
‘uiNormalizeMPI()’ is the same as ‘normalizeMPI()’ except that ‘aMpi’ is expected to be non-begative.
Definition int_int.h:233
InternalCF * sqrt()
InternalCF * InternalInteger::sqrt ()
Definition int_int.cc:529
InternalInteger(const mpz_ptr mpi)
Definition int_int.h:94
InternalInteger(const long i)
Definition int_int.h:91
friend void gmp_denominator(const CanonicalForm &f, mpz_ptr result)
Definition singext.cc:40
static const omBin InternalInteger_bin
Definition int_int.h:69
void divremcoeff(InternalCF *, InternalCF *&, InternalCF *&, bool)
friend class InternalRational
Definition int_int.h:149
InternalInteger(const char *str, const int base=10)
Definition int_int.h:92
int levelcoeff() const
Definition int_int.h:106
long intval() const
Definition int_int.cc:506
const char * classname() const
Definition int_int.h:97
InternalCF * modcoeff(InternalCF *, bool)
InternalCF * mulsame(InternalCF *)
Definition int_int.cc:147
InternalCF * modulocoeff(InternalCF *, bool)
int ilog2()
int InternalInteger::ilog2 ()
Definition int_int.cc:549
InternalCF * bgcdcoeff(const InternalCF *const)
Definition int_int.cc:377
InternalCF * genOne()
Definition int_int.cc:54
InternalCF * genZero()
Definition int_int.cc:46
int sign() const
int InternalInteger::sign () const
Definition int_int.cc:520
InternalCF * modulosame(InternalCF *)
InternalCF * divcoeff(InternalCF *, bool)
void divremsame(InternalCF *, InternalCF *&, InternalCF *&)
InternalCF * addcoeff(InternalCF *)
Definition int_int.cc:205
InternalCF * subcoeff(InternalCF *, bool)
Definition int_int.cc:244
static InternalCF * normalizeMPI(mpz_ptr)
normalizeMPI(), uiNormalizeMPI() - normalize a mpi.
Definition int_int.h:216
InternalCF * bgcdsame(const InternalCF *const) const
Definition int_int.cc:348
bool divremsamet(InternalCF *, InternalCF *&, InternalCF *&)
InternalCF * bextgcdsame(InternalCF *, CanonicalForm &, CanonicalForm &)
Definition int_int.cc:409
bool is_imm() const
Definition int_int.cc:41
InternalCF * subsame(InternalCF *)
Definition int_int.cc:116
InternalCF * dividesame(InternalCF *)
Definition int_intdiv.cc:28
InternalCF * divsame(InternalCF *)
friend void convertCF2Fmpq(fmpq_t result, const CanonicalForm &f)
conversion of a factory rationals to fmpq_t
InternalCF * bextgcdcoeff(InternalCF *, CanonicalForm &, CanonicalForm &)
Definition int_int.cc:464
InternalCF * mulcoeff(InternalCF *)
Definition int_int.cc:299
InternalCF * neg()
InternalCF * InternalInteger::neg ()
Definition int_int.cc:66
InternalInteger(const int i)
Definition int_int.h:90
friend void gmp_numerator(const CanonicalForm &f, mpz_ptr result)
Definition singext.cc:20
void print(OSTREAM &, char *)
Definition int_int.cc:26
int comparesame(InternalCF *)
Definition int_int.cc:188
int comparecoeff(InternalCF *)
Definition int_int.cc:198
friend void getmpi(InternalCF *value, mpz_t mpi)
static mpz_ptr MPI(const InternalCF *const c)
MPI() - return underlying mpz_t of ‘c’.
Definition int_int.h:252
InternalCF * addsame(InternalCF *)
Definition int_int.cc:85
int intmod(int p) const
Definition int_int.cc:511
friend void convertCF2initFmpz(fmpz_t result, const CanonicalForm &f)
conversion of a factory integer to fmpz_t(init.)
friend void convertCF2Fmpz(fmpz *, const CanonicalForm &)
InternalCF * uiNormalizeMyself()
‘uiNormalizeMyself()’ is the same as ‘normalizeMyself()’ except that CO is expected to be non-negativ...
Definition int_int.h:194
bool divremcoefft(InternalCF *, InternalCF *&, InternalCF *&, bool)
return result
utility functions for gmp
bool mpz_is_imm(const mpz_t mpi)
Definition gmpext.h:19
static InternalCF * int2imm(long i)
Definition imm.h:75
Factory's internal CanonicalForm's.
#define omTypeAllocBin(type, addr, bin)
#define omFreeBin(addr, bin)
omBin_t * omBin
Definition omStructs.h:12