MCPcopy Create free account
hub / github.com/Singular/Singular / QToZVectorPrimitive

Function QToZVectorPrimitive

gfanlib/gfanlib_vector.h:343–405  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

341}
342
343inline ZVector QToZVectorPrimitive(QVector const &v)
344{
345 int n=v.size();
346 ZVector ret(n);
347
348 mpz_t lcm;
349 mpz_t gcd;
350 mpz_init_set_ui(lcm, 1);
351 mpz_init_set_ui(gcd, 0);
352
353 mpq_t a;
354 mpq_init(a);
355 for(int j=0;j<n;j++)
356 {
357 v[j].setGmp(a);
358 if(mpz_cmp_si(mpq_denref(a),1)!=0)
359 mpz_lcm(lcm,lcm,mpq_denref(a));
360 if(mpz_sgn(mpq_numref(a))!=0)
361 mpz_gcd(gcd,gcd,mpq_numref(a));
362 }
363 mpq_clear(a);
364 if(mpz_sgn(gcd)!=0)//v is non-zero
365 {
366 if((mpz_cmp_si(lcm,1)==0)&&(mpz_cmp_si(gcd,1)==0)) //gcd=lcm=1
367 {
368 mpq_t a;
369 mpq_init(a);
370
371 for(int i=0;i<n;i++)
372 {
373 v[i].setGmp(a);
374 ret[i]=Integer(mpq_numref(a));
375 }
376 mpq_clear(a);
377 }
378 else
379 {
380 mpq_t a;
381 mpq_init(a);
382 mpz_t tempA;
383 mpz_t tempB;
384 mpz_init(tempA);
385 mpz_init(tempB);
386 for(int i=0;i<n;i++)
387 {
388 v[i].setGmp(a);
389 mpz_set(tempA,mpq_denref(a));
390 mpz_set(tempB,mpq_numref(a));
391 mpz_mul(tempA,gcd,tempA);
392 mpz_mul(tempB,lcm,tempB);
393 mpz_divexact(tempA,tempB,tempA);
394 ret[i]=Integer(tempA);
395 }
396 mpz_clear(tempB);
397 mpz_clear(tempA);
398 mpq_clear(a);
399 }
400 }

Callers 6

getConstraintsMethod · 0.85
removeRedundantRowsMethod · 0.85
relativeInteriorPointMethod · 0.85
ensureStateAsMinimumMethod · 0.85
extremeRaysMethod · 0.85
QToZMatrixPrimitiveFunction · 0.85

Calls 3

IntegerClass · 0.85
sizeMethod · 0.45
setGmpMethod · 0.45

Tested by

no test coverage detected