My Project  debian-1:4.1.2-p1+ds-2
Data Structures | Macros | Functions
longrat.h File Reference
#include "misc/auxiliary.h"
#include "coeffs/si_gmp.h"
#include "coeffs/coeffs.h"

Go to the source code of this file.

Data Structures

struct  number
 'SR_INT' is the type of those integers small enough to fit into 29 bits. More...
 

Macros

#define SR_HDL(A)   ((long)(A))
 
#define SR_INT   1L
 
#define INT_TO_SR(INT)   ((number) (((long)INT << 2) + SR_INT))
 
#define SR_TO_INT(SR)   (((long)SR) >> 2)
 
#define MP_SMALL   1
 

Functions

number nlGetDenom (number &n, const coeffs r)
 
number nlGetNumerator (number &n, const coeffs r)
 
BOOLEAN nlInitChar (coeffs, void *)
 
static FORCE_INLINE int nlQlogSize (number n, const coeffs r)
 only used by slimgb (tgb.cc) More...
 
static FORCE_INLINE BOOLEAN nlIsInteger (number q, const coeffs r)
 
number nlModP (number q, const coeffs Q, const coeffs Zp)
 
void nlNormalize (number &x, const coeffs r)
 
void nlInpGcd (number &a, number b, const coeffs r)
 
void nlDelete (number *a, const coeffs r)
 
number nlInit2 (int i, int j, const coeffs r)
 create a rational i/j (implicitly) over Q NOTE: make sure to use correct Q in debug mode More...
 
number nlInit2gmp (mpz_t i, mpz_t j, const coeffs r)
 create a rational i/j (implicitly) over Q NOTE: make sure to use correct Q in debug mode More...
 
void nlGMP (number &i, mpz_t n, const coeffs r)
 
number nlMapGMP (number from, const coeffs src, const coeffs dst)
 
number nlChineseRemainderSym (number *x, number *q, int rl, BOOLEAN sym, CFArray &inv_cache, const coeffs CF)
 

Data Structure Documentation

◆ snumber

struct snumber

'SR_INT' is the type of those integers small enough to fit into 29 bits.

Therefor the value range of this small integers is: $-2^{28}...2^{28}-1$.

Small integers are represented by an immediate integer handle, containing the value instead of pointing to it, which has the following form:

+-------+-------+-------+-------+- - - -+-------+-------+-------+
| guard | sign  | bit   | bit   |       | bit   | tag   | tag   |
| bit   | bit   | 27    | 26    |       | 0     | 0     | 1     |
+-------+-------+-------+-------+- - - -+-------+-------+-------+

Immediate integers handles carry the tag 'SR_INT', i.e. the last bit is 1. This distuingishes immediate integers from other handles which point to structures aligned on 4 byte boundaries and therefor have last bit zero. (The second bit is reserved as tag to allow extensions of this scheme.) Using immediates as pointers and dereferencing them gives address errors.

To aid overflow check the most significant two bits must always be equal, that is to say that the sign bit of immediate integers has a guard bit.

The macros 'INT_TO_SR' and 'SR_TO_INT' should be used to convert between a small integer value and its representation as immediate integer handle.

Large integers and rationals are represented by z and n where n may be undefined (if s==3) NULL represents only deleted values

Definition at line 47 of file longrat.h.

Data Fields
int debug
mpz_t n
BOOLEAN s parameter s in number: 0 (or FALSE): not normalised rational 1 (or TRUE): normalised rational 3 : integer with n==NULL
mpz_t z

Macro Definition Documentation

◆ INT_TO_SR

#define INT_TO_SR (   INT)    ((number) (((long)INT << 2) + SR_INT))

Definition at line 67 of file longrat.h.

◆ MP_SMALL

#define MP_SMALL   1

Definition at line 70 of file longrat.h.

◆ SR_HDL

#define SR_HDL (   A)    ((long)(A))

Definition at line 64 of file longrat.h.

◆ SR_INT

#define SR_INT   1L

Definition at line 66 of file longrat.h.

◆ SR_TO_INT

#define SR_TO_INT (   SR)    (((long)SR) >> 2)

Definition at line 68 of file longrat.h.

Function Documentation

◆ nlChineseRemainderSym()

number nlChineseRemainderSym ( number *  x,
number *  q,
int  rl,
BOOLEAN  sym,
CFArray inv_cache,
const coeffs  CF 
)

Definition at line 2938 of file longrat.cc.

2940 {
2941  setCharacteristic( 0 ); // only in char 0
2942  Off(SW_RATIONAL);
2943  CFArray X(rl), Q(rl);
2944  int i;
2945  for(i=rl-1;i>=0;i--)
2946  {
2947  X[i]=CF->convSingNFactoryN(x[i],FALSE,CF); // may be larger MAX_INT
2948  Q[i]=CF->convSingNFactoryN(q[i],FALSE,CF); // may be larger MAX_INT
2949  }
2950  CanonicalForm xnew,qnew;
2951  if (n_SwitchChinRem)
2952  chineseRemainder(X,Q,xnew,qnew);
2953  else
2954  chineseRemainderCached(X,Q,xnew,qnew,inv_cache);
2955  number n=CF->convFactoryNSingN(xnew,CF);
2956  if (sym)
2957  {
2958  number p=CF->convFactoryNSingN(qnew,CF);
2959  number p2;
2960  if (getCoeffType(CF) == n_Q) p2=nlIntDiv(p,nlInit(2, CF),CF);
2961  else p2=CF->cfDiv(p,CF->cfInit(2, CF),CF);
2962  if (CF->cfGreater(n,p2,CF))
2963  {
2964  number n2=CF->cfSub(n,p,CF);
2965  CF->cfDelete(&n,CF);
2966  n=n2;
2967  }
2968  CF->cfDelete(&p2,CF);
2969  CF->cfDelete(&p,CF);
2970  }
2971  CF->cfNormalize(n,CF);
2972  return n;
2973 }
#define FALSE
Definition: auxiliary.h:96
void Off(int sw)
switches
void setCharacteristic(int c)
Definition: cf_char.cc:23
int i
Definition: cfEzgcd.cc:125
Variable x
Definition: cfModGcd.cc:4023
int p
Definition: cfModGcd.cc:4019
void chineseRemainder(const CanonicalForm &x1, const CanonicalForm &q1, const CanonicalForm &x2, const CanonicalForm &q2, CanonicalForm &xnew, CanonicalForm &qnew)
void chineseRemainder ( const CanonicalForm & x1, const CanonicalForm & q1, const CanonicalForm & x2,...
Definition: cf_chinese.cc:52
void chineseRemainderCached(CFArray &a, CFArray &n, CanonicalForm &xnew, CanonicalForm &prod, CFArray &inv)
Definition: cf_chinese.cc:265
static const int SW_RATIONAL
set to 1 for computations over Q
Definition: cf_defs.h:29
factory's main class
Definition: canonicalform.h:83
@ n_Q
rational (GMP) numbers
Definition: coeffs.h:31
static FORCE_INLINE n_coeffType getCoeffType(const coeffs r)
Returns the type of coeffs domain.
Definition: coeffs.h:421
STATIC_VAR jList * Q
Definition: janet.cc:30
VAR int n_SwitchChinRem
Definition: longrat.cc:2937
number nlIntDiv(number a, number b, const coeffs r)
Definition: longrat.cc:795
LINLINE number nlInit(long i, const coeffs r)
Definition: longrat.cc:2437

◆ nlDelete()

void nlDelete ( number *  a,
const coeffs  r 
)

Definition at line 2497 of file longrat.cc.

2498 {
2499  if (*a!=NULL)
2500  {
2501  nlTest(*a, r);
2502  if ((SR_HDL(*a) & SR_INT)==0)
2503  {
2504  _nlDelete_NoImm(a);
2505  }
2506  *a=NULL;
2507  }
2508 }
#define nlTest(a, r)
Definition: longrat.cc:92
void _nlDelete_NoImm(number *a)
Definition: longrat.cc:1626
#define SR_INT
Definition: longrat.h:66
#define NULL
Definition: omList.c:12
#define SR_HDL(A)
Definition: tgb.cc:35

◆ nlGetDenom()

number nlGetDenom ( number &  n,
const coeffs  r 
)

Definition at line 1498 of file longrat.cc.

1499 {
1500  if (!(SR_HDL(n) & SR_INT))
1501  {
1502  if (n->s==0)
1503  {
1504  nlNormalize(n,r);
1505  }
1506  if (!(SR_HDL(n) & SR_INT))
1507  {
1508  if (n->s!=3)
1509  {
1510  number u=ALLOC_RNUMBER();
1511  u->s=3;
1512 #if defined(LDEBUG)
1513  u->debug=123456;
1514 #endif
1515  mpz_init_set(u->z,n->n);
1516  u=nlShort3_noinline(u);
1517  return u;
1518  }
1519  }
1520  }
1521  return INT_TO_SR(1);
1522 }
#define ALLOC_RNUMBER()
Definition: coeffs.h:87
number nlShort3_noinline(number x)
Definition: longrat.cc:164
void nlNormalize(number &x, const coeffs r)
Definition: longrat.cc:1344
#define INT_TO_SR(INT)
Definition: longrat.h:67

◆ nlGetNumerator()

number nlGetNumerator ( number &  n,
const coeffs  r 
)

Definition at line 1527 of file longrat.cc.

1528 {
1529  if (!(SR_HDL(n) & SR_INT))
1530  {
1531  if (n->s==0)
1532  {
1533  nlNormalize(n,r);
1534  }
1535  if (!(SR_HDL(n) & SR_INT))
1536  {
1537  number u=ALLOC_RNUMBER();
1538 #if defined(LDEBUG)
1539  u->debug=123456;
1540 #endif
1541  u->s=3;
1542  mpz_init_set(u->z,n->z);
1543  if (n->s!=3)
1544  {
1545  u=nlShort3_noinline(u);
1546  }
1547  return u;
1548  }
1549  }
1550  return n; // imm. int
1551 }

◆ nlGMP()

void nlGMP ( number &  i,
mpz_t  n,
const coeffs  r 
)

Definition at line 1477 of file longrat.cc.

1478 {
1479  // Hier brauche ich einfach die GMP Zahl
1480  nlTest(i, r);
1481  nlNormalize(i, r);
1482  if (SR_HDL(i) & SR_INT)
1483  {
1484  mpz_set_si(n, SR_TO_INT(i));
1485  return;
1486  }
1487  if (i->s!=3)
1488  {
1489  WarnS("Omitted denominator during coefficient mapping !");
1490  }
1491  mpz_set(n, i->z);
1492 }
#define WarnS
Definition: emacs.cc:78
#define SR_TO_INT(SR)
Definition: longrat.h:68

◆ nlInit2()

number nlInit2 ( int  i,
int  j,
const coeffs  r 
)

create a rational i/j (implicitly) over Q NOTE: make sure to use correct Q in debug mode

Definition at line 2375 of file longrat.cc.

2376 {
2377  number z=ALLOC_RNUMBER();
2378 #if defined(LDEBUG)
2379  z->debug=123456;
2380 #endif
2381  mpz_init_set_si(z->z,(long)i);
2382  mpz_init_set_si(z->n,(long)j);
2383  z->s = 0;
2384  nlNormalize(z,r);
2385  return z;
2386 }
int j
Definition: facHensel.cc:105

◆ nlInit2gmp()

number nlInit2gmp ( mpz_t  i,
mpz_t  j,
const coeffs  r 
)

create a rational i/j (implicitly) over Q NOTE: make sure to use correct Q in debug mode

Definition at line 2388 of file longrat.cc.

2389 {
2390  number z=ALLOC_RNUMBER();
2391 #if defined(LDEBUG)
2392  z->debug=123456;
2393 #endif
2394  mpz_init_set(z->z,i);
2395  mpz_init_set(z->n,j);
2396  z->s = 0;
2397  nlNormalize(z,r);
2398  return z;
2399 }

◆ nlInitChar()

BOOLEAN nlInitChar ( coeffs  r,
void *  p 
)

Definition at line 3325 of file longrat.cc.

3326 {
3327  r->is_domain=TRUE;
3328  r->rep=n_rep_gap_rat;
3329 
3330  r->nCoeffIsEqual=nlCoeffIsEqual;
3331  //r->cfKillChar = ndKillChar; /* dummy */
3332  r->cfCoeffString=nlCoeffString;
3333  r->cfCoeffName=nlCoeffName;
3334 
3335  r->cfInitMPZ = nlInitMPZ;
3336  r->cfMPZ = nlMPZ;
3337 
3338  r->cfMult = nlMult;
3339  r->cfSub = nlSub;
3340  r->cfAdd = nlAdd;
3341  r->cfExactDiv= nlExactDiv;
3342  if (p==NULL) /* Q */
3343  {
3344  r->is_field=TRUE;
3345  r->cfDiv = nlDiv;
3346  //r->cfGcd = ndGcd_dummy;
3347  r->cfSubringGcd = nlGcd;
3348  }
3349  else /* Z: coeffs_BIGINT */
3350  {
3351  r->is_field=FALSE;
3352  r->cfDiv = nlIntDiv;
3353  r->cfIntMod= nlIntMod;
3354  r->cfGcd = nlGcd;
3355  r->cfDivBy=nlDivBy;
3356  r->cfDivComp = nlDivComp;
3357  r->cfIsUnit = nlIsUnit;
3358  r->cfGetUnit = nlGetUnit;
3359  r->cfQuot1 = nlQuot1;
3360  r->cfLcm = nlLcm;
3361  r->cfXExtGcd=nlXExtGcd;
3362  r->cfQuotRem=nlQuotRem;
3363  }
3364  r->cfInit = nlInit;
3365  r->cfSize = nlSize;
3366  r->cfInt = nlInt;
3367 
3368  r->cfChineseRemainder=nlChineseRemainderSym;
3369  r->cfFarey=nlFarey;
3370  r->cfInpNeg = nlNeg;
3371  r->cfInvers= nlInvers;
3372  r->cfCopy = nlCopy;
3373  r->cfRePart = nlCopy;
3374  //r->cfImPart = ndReturn0;
3375  r->cfWriteLong = nlWrite;
3376  r->cfRead = nlRead;
3377  r->cfNormalize=nlNormalize;
3378  r->cfGreater = nlGreater;
3379  r->cfEqual = nlEqual;
3380  r->cfIsZero = nlIsZero;
3381  r->cfIsOne = nlIsOne;
3382  r->cfIsMOne = nlIsMOne;
3383  r->cfGreaterZero = nlGreaterZero;
3384  r->cfPower = nlPower;
3385  r->cfGetDenom = nlGetDenom;
3386  r->cfGetNumerator = nlGetNumerator;
3387  r->cfExtGcd = nlExtGcd; // only for ring stuff and Z
3388  r->cfNormalizeHelper = nlNormalizeHelper;
3389  r->cfDelete= nlDelete;
3390  r->cfSetMap = nlSetMap;
3391  //r->cfName = ndName;
3392  r->cfInpMult=nlInpMult;
3393  r->cfInpAdd=nlInpAdd;
3394  r->cfCoeffWrite=nlCoeffWrite;
3395 
3396  r->cfClearContent = nlClearContent;
3397  r->cfClearDenominators = nlClearDenominators;
3398 
3399 #ifdef LDEBUG
3400  // debug stuff
3401  r->cfDBTest=nlDBTest;
3402 #endif
3403  r->convSingNFactoryN=nlConvSingNFactoryN;
3404  r->convFactoryNSingN=nlConvFactoryNSingN;
3405 
3406  r->cfRandom=nlRandom;
3407 
3408  // io via ssi
3409  r->cfWriteFd=nlWriteFd;
3410  r->cfReadFd=nlReadFd;
3411 
3412  //r->type = n_Q;
3413  r->ch = 0;
3414  r->has_simple_Alloc=FALSE;
3415  r->has_simple_Inverse=FALSE;
3416 
3417  // variables for this type of coeffs:
3418  // (none)
3419  return FALSE;
3420 }
#define TRUE
Definition: auxiliary.h:100
@ n_rep_gap_rat
(number), see longrat.h
Definition: coeffs.h:111
static void nlMPZ(mpz_t m, number &n, const coeffs r)
Definition: longrat.cc:2650
void nlWriteFd(number n, const ssiInfo *d, const coeffs)
Definition: longrat.cc:3180
LINLINE void nlInpMult(number &a, number b, const coeffs r)
Definition: longrat.cc:2616
LINLINE BOOLEAN nlEqual(number a, number b, const coeffs r)
Definition: longrat.cc:2428
LINLINE number nlAdd(number la, number li, const coeffs r)
Definition: longrat.cc:2532
long nlInt(number &n, const coeffs r)
Definition: longrat.cc:598
static number nlLcm(number a, number b, const coeffs r)
Definition: longrat.cc:3301
const char * nlRead(const char *s, number *a, const coeffs r)
Definition: longrat0.cc:31
LINLINE number nlSub(number la, number li, const coeffs r)
Definition: longrat.cc:2598
number nlIntMod(number a, number b, const coeffs r)
Definition: longrat.cc:876
LINLINE number nlCopy(number a, const coeffs r)
Definition: longrat.cc:2484
LINLINE number nlNeg(number za, const coeffs r)
Definition: longrat.cc:2513
number nlXExtGcd(number a, number b, number *s, number *t, number *u, number *v, const coeffs r)
Definition: longrat.cc:2671
void nlPower(number x, int exp, number *lu, const coeffs r)
Definition: longrat.cc:1112
number nlQuotRem(number a, number b, number *r, const coeffs R)
Definition: longrat.cc:2723
number nlFarey(number nN, number nP, const coeffs CF)
Definition: longrat.cc:2809
LINLINE BOOLEAN nlIsOne(number a, const coeffs r)
Definition: longrat.cc:2455
number nlNormalizeHelper(number a, number b, const coeffs r)
Definition: longrat.cc:1388
LINLINE void nlDelete(number *a, const coeffs r)
Definition: longrat.cc:2497
BOOLEAN nlGreaterZero(number za, const coeffs r)
Definition: longrat.cc:1165
LINLINE void nlInpAdd(number &a, number b, const coeffs r)
Definition: longrat.cc:2550
number nlExactDiv(number a, number b, const coeffs r)
Definition: longrat.cc:728
number nlInvers(number a, const coeffs r)
Definition: longrat.cc:648
BOOLEAN nlIsUnit(number a, const coeffs)
Definition: longrat.cc:993
static number nlConvFactoryNSingN(const CanonicalForm f, const coeffs r)
Definition: longrat.cc:369
number nlChineseRemainderSym(number *x, number *q, int rl, BOOLEAN sym, CFArray &inv_cache, const coeffs CF)
Definition: longrat.cc:2938
int nlDivComp(number a, number b, const coeffs r)
Definition: longrat.cc:951
number nlExtGcd(number a, number b, number *s, number *t, const coeffs)
Definition: longrat.cc:2880
LINLINE number nlMult(number a, number b, const coeffs r)
Definition: longrat.cc:2568
static number nlInitMPZ(mpz_t m, const coeffs)
Definition: longrat.cc:2659
static void nlClearDenominators(ICoeffsEnumerator &numberCollectionEnumerator, number &c, const coeffs cf)
Definition: longrat.cc:3073
LINLINE BOOLEAN nlIsZero(number za, const coeffs r)
Definition: longrat.cc:2464
number nlGetDenom(number &n, const coeffs r)
Definition: longrat.cc:1498
number nlGcd(number a, number b, const coeffs r)
Definition: longrat.cc:1202
number nlReadFd(const ssiInfo *d, const coeffs)
Definition: longrat.cc:3226
int nlSize(number a, const coeffs)
Definition: longrat.cc:569
nMapFunc nlSetMap(const coeffs src, const coeffs dst)
Definition: longrat.cc:2324
char * nlCoeffName(const coeffs r)
Definition: longrat.cc:3167
BOOLEAN nlDBTest(number a, const char *f, const int l)
static char * nlCoeffString(const coeffs r)
Definition: longrat.cc:3173
number nlDiv(number a, number b, const coeffs r)
Definition: longrat.cc:1002
BOOLEAN nlIsMOne(number a, const coeffs r)
Definition: longrat.cc:1190
static void nlClearContent(ICoeffsEnumerator &numberCollectionEnumerator, number &c, const coeffs cf)
Definition: longrat.cc:2982
number nlGetNumerator(number &n, const coeffs r)
Definition: longrat.cc:1527
BOOLEAN nlCoeffIsEqual(const coeffs r, n_coeffType n, void *p)
Definition: longrat.cc:3289
static CanonicalForm nlConvSingNFactoryN(number n, const BOOLEAN setChar, const coeffs)
Definition: longrat.cc:331
number nlGetUnit(number n, const coeffs cf)
Definition: longrat.cc:962
coeffs nlQuot1(number c, const coeffs r)
Definition: longrat.cc:968
BOOLEAN nlGreater(number a, number b, const coeffs r)
Definition: longrat.cc:1175
void nlCoeffWrite(const coeffs r, BOOLEAN details)
Definition: longrat.cc:2929
BOOLEAN nlDivBy(number a, number b, const coeffs)
Definition: longrat.cc:937
void nlWrite(number a, const coeffs r)
Definition: longrat0.cc:90
static number nlRandom(siRandProc p, number v2, number, const coeffs cf)
Definition: longrat.cc:3311

◆ nlInpGcd()

void nlInpGcd ( number &  a,
number  b,
const coeffs  r 
)

Definition at line 2776 of file longrat.cc.

2777 {
2778  if ((SR_HDL(b)|SR_HDL(a))&SR_INT)
2779  {
2780  number n=nlGcd(a,b,r);
2781  nlDelete(&a,r);
2782  a=n;
2783  }
2784  else
2785  {
2786  mpz_gcd(a->z,a->z,b->z);
2787  a=nlShort3_noinline(a);
2788  }
2789 }
CanonicalForm b
Definition: cfModGcd.cc:4044

◆ nlIsInteger()

static FORCE_INLINE BOOLEAN nlIsInteger ( number  q,
const coeffs  r 
)
static

Definition at line 93 of file longrat.h.

94 {
95  assume( nCoeff_is_Q (r) );
96  n_Test(q, r);
97 
98  if (SR_HDL(q) & SR_INT)
99  return TRUE; // immediate int
100 
101  return ( q->s == 3 );
102 }
#define n_Test(a, r)
BOOLEAN n_Test(number a, const coeffs r)
Definition: coeffs.h:738
static FORCE_INLINE BOOLEAN nCoeff_is_Q(const coeffs r)
Definition: coeffs.h:828
#define SR_HDL(A)
Definition: longrat.h:64
#define assume(x)
Definition: mod2.h:390

◆ nlMapGMP()

number nlMapGMP ( number  from,
const coeffs  src,
const coeffs  dst 
)

Definition at line 200 of file longrat.cc.

201 {
202  number z=ALLOC_RNUMBER();
203 #if defined(LDEBUG)
204  z->debug=123456;
205 #endif
206  mpz_init_set(z->z,(mpz_ptr) from);
207  z->s = 3;
208  z=nlShort3(z);
209  return z;
210 }
static number nlShort3(number x)
Definition: longrat.cc:114

◆ nlModP()

number nlModP ( number  q,
const coeffs  Q,
const coeffs  Zp 
)

Definition at line 1435 of file longrat.cc.

1436 {
1437  const int p = n_GetChar(Zp);
1438  assume( p > 0 );
1439 
1440  const long P = p;
1441  assume( P > 0 );
1442 
1443  // embedded long within q => only long numerator has to be converted
1444  // to int (modulo char.)
1445  if (SR_HDL(q) & SR_INT)
1446  {
1447  long i = SR_TO_INT(q);
1448  return n_Init( i, Zp );
1449  }
1450 
1451  const unsigned long PP = p;
1452 
1453  // numerator modulo char. should fit into int
1454  number z = n_Init( static_cast<long>(mpz_fdiv_ui(q->z, PP)), Zp );
1455 
1456  // denominator != 1?
1457  if (q->s!=3)
1458  {
1459  // denominator modulo char. should fit into int
1460  number n = n_Init( static_cast<long>(mpz_fdiv_ui(q->n, PP)), Zp );
1461 
1462  number res = n_Div( z, n, Zp );
1463 
1464  n_Delete(&z, Zp);
1465  n_Delete(&n, Zp);
1466 
1467  return res;
1468  }
1469 
1470  return z;
1471 }
static FORCE_INLINE number n_Div(number a, number b, const coeffs r)
return the quotient of 'a' and 'b', i.e., a/b; raises an error if 'b' is not invertible in r exceptio...
Definition: coeffs.h:615
static FORCE_INLINE int n_GetChar(const coeffs r)
Return the characteristic of the coeff. domain.
Definition: coeffs.h:444
static FORCE_INLINE void n_Delete(number *p, const coeffs r)
delete 'p'
Definition: coeffs.h:455
static FORCE_INLINE number n_Init(long i, const coeffs r)
a number representing i in the given coeff field/ring r
Definition: coeffs.h:538
CanonicalForm res
Definition: facAbsFact.cc:64

◆ nlNormalize()

void nlNormalize ( number &  x,
const coeffs  r 
)

Definition at line 1344 of file longrat.cc.

1345 {
1346  if ((SR_HDL(x) & SR_INT) ||(x==NULL))
1347  return;
1348  if (x->s==3)
1349  {
1351  nlTest(x,r);
1352  return;
1353  }
1354  else if (x->s==0)
1355  {
1356  if (mpz_cmp_si(x->n,1L)==0)
1357  {
1358  mpz_clear(x->n);
1359  x->s=3;
1360  x=nlShort3(x);
1361  }
1362  else
1363  {
1364  mpz_t gcd;
1365  mpz_init(gcd);
1366  mpz_gcd(gcd,x->z,x->n);
1367  x->s=1;
1368  if (mpz_cmp_si(gcd,1L)!=0)
1369  {
1370  mpz_divexact(x->z,x->z,gcd);
1371  mpz_divexact(x->n,x->n,gcd);
1372  if (mpz_cmp_si(x->n,1L)==0)
1373  {
1374  mpz_clear(x->n);
1375  x->s=3;
1377  }
1378  }
1379  mpz_clear(gcd);
1380  }
1381  }
1382  nlTest(x, r);
1383 }
int gcd(int a, int b)
Definition: walkSupport.cc:836

◆ nlQlogSize()

static FORCE_INLINE int nlQlogSize ( number  n,
const coeffs  r 
)
static

only used by slimgb (tgb.cc)

Definition at line 75 of file longrat.h.

76 {
77  assume( nCoeff_is_Q (r) );
78 
79  if(SR_HDL(n)&SR_INT)
80  {
81  if (SR_HDL(n)==SR_INT) return 0;
82  long i = SR_TO_INT (n);
83  unsigned long v;
84  v = ABS(i);
85  return SI_LOG2(v) + 1;
86  }
87  //assume denominator is 0
88  number nn=(number) n;
89  return mpz_sizeinbase (nn->z, 2);
90 }
static int ABS(int v)
Definition: auxiliary.h:112
static int SI_LOG2(int v)
Definition: auxiliary.h:121
const Variable & v
< [in] a sqrfree bivariate poly
Definition: facBivar.h:37