Macaulay2 Engine
Loading...
Searching...
No Matches

◆ toInteger()

__mpz_struct toInteger ( CanonicalForm h)
static

we don't have access to int_cf.h and int_int.h from factory, so the following commented-out code won't compile; but it might have worked.

Definition at line 170 of file factory.cpp.

171{
174 // struct enter_factory foo;
175 // assert(h.inZ());
176 // InternalCF *value = h.getval();
177 // MP_INT y = value->MPI();
178 // mpz_t x;
179 // mpz_init(x);
180 // mpz_set(x,y);
181 // return *x;
182 static const unsigned int base = 1 << 16;
183 gc_vector<int> vec;
184 int sign;
185 {
186 struct enter_factory foo;
187 int RationalMode = isOn(SW_RATIONAL) ? (Off(SW_RATIONAL), 1) : 0;
188 if (h < 0)
189 {
190 sign = -1;
191 h = -h;
192 }
193 else
194 sign = 1;
195 while (h != 0)
196 {
197 CanonicalForm k = h % (int)base;
198 vec.push_back(static_cast<int>(k.intval()));
199 h = h / (int)base;
200 }
201 if (RationalMode) On(SW_RATIONAL);
202 }
203 mpz_t x;
204 mpz_init(x);
205 for (int i = vec.size() - 1; i >= 0; i--)
206 {
207 mpz_mul_ui(x, x, base); // x = x * base;
208 mpz_add_ui(x, x, static_cast<unsigned>(vec[i]));
209 }
210 if (sign == -1) mpz_neg(x, x); // x = -x;
211 return x[0];
212}
static CanonicalForm base
Definition factory.cpp:289
typename std::vector< T, gc_allocator< T > > gc_vector
a version of the STL vector, which allocates its backing memory with gc.
Definition newdelete.hpp:76
volatile int x

References base, and x.

Referenced by convertToM2().