My Project
Loading...
Searching...
No Matches
longrat.h File Reference
#include "misc/auxiliary.h"
#include "coeffs/si_gmp.h"
#include "coeffs/coeffs.h"
#include "factory/si_log2.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)
#define SR_INT   1L
#define INT_TO_SR(INT)
#define SR_TO_INT(SR)
#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)
static FORCE_INLINE BOOLEAN nlIsInteger (number q, const coeffs r)
void nlMPZ (mpz_t m, number &n, const coeffs r)
 get numerator as mpz_t
void nlMPZ2 (mpz_t m, number &n, const coeffs r)
 get demoninator as mpz_t
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
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
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.

Therefore 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 distinguishes immediate integers from other handles which point to structures aligned on 4 byte boundaries and therefore 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 48 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)
Value:
((number) (((long)INT << 2) + SR_INT))
#define SR_INT
Definition longrat.h:67

Definition at line 68 of file longrat.h.

◆ MP_SMALL

#define MP_SMALL   1

Definition at line 71 of file longrat.h.

◆ SR_HDL

#define SR_HDL ( A)
Value:
((long)(A))
#define A
Definition sirandom.c:24

Definition at line 65 of file longrat.h.

◆ SR_INT

#define SR_INT   1L

Definition at line 67 of file longrat.h.

◆ SR_TO_INT

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

Definition at line 69 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 3076 of file longrat.cc.

3078{
3079 setCharacteristic( 0 ); // only in char 0
3081 CFArray X(rl), Q(rl);
3082 int i;
3083 for(i=rl-1;i>=0;i--)
3084 {
3085 X[i]=CF->convSingNFactoryN(x[i],FALSE,CF); // may be larger MAX_INT
3086 Q[i]=CF->convSingNFactoryN(q[i],FALSE,CF); // may be larger MAX_INT
3087 }
3088 CanonicalForm xnew,qnew;
3089 if (n_SwitchChinRem)
3090 chineseRemainder(X,Q,xnew,qnew);
3091 else
3092 chineseRemainderCached(X,Q,xnew,qnew,inv_cache);
3093 number n=CF->convFactoryNSingN(xnew,CF);
3094 if (sym)
3095 {
3096 number p=CF->convFactoryNSingN(qnew,CF);
3097 number p2;
3098 if (getCoeffType(CF) == n_Q) p2=nlIntDiv(p,nlInit(2, CF),CF);
3099 else p2=CF->cfDiv(p,CF->cfInit(2, CF),CF);
3100 if (CF->cfGreater(n,p2,CF))
3101 {
3102 number n2=CF->cfSub(n,p,CF);
3103 CF->cfDelete(&n,CF);
3104 n=n2;
3105 }
3106 CF->cfDelete(&p2,CF);
3107 CF->cfDelete(&p,CF);
3108 }
3109 CF->cfNormalize(n,CF);
3110 return n;
3111}
#define FALSE
Definition auxiliary.h:97
void Off(int sw)
switches
Array< CanonicalForm > CFArray
void FACTORY_PUBLIC setCharacteristic(int c)
Definition cf_char.cc:28
int i
Definition cfEzgcd.cc:132
Variable x
Definition cfModGcd.cc:4090
int p
Definition cfModGcd.cc:4086
void FACTORY_PUBLIC 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:57
void FACTORY_PUBLIC chineseRemainderCached(const CanonicalForm &x1, const CanonicalForm &q1, const CanonicalForm &x2, const CanonicalForm &q2, CanonicalForm &xnew, CanonicalForm &qnew, CFArray &inv)
static const int SW_RATIONAL
set to 1 for computations over Q
Definition cf_defs.h:31
factory's main class
@ n_Q
rational (GMP) numbers
Definition coeffs.h:30
static FORCE_INLINE n_coeffType getCoeffType(const coeffs r)
Returns the type of coeffs domain.
Definition coeffs.h:431
VAR int n_SwitchChinRem
Definition longrat.cc:3075
number nlIntDiv(number a, number b, const coeffs r)
Definition longrat.cc:936
LINLINE number nlInit(long i, const coeffs r)
Definition longrat.cc:2578
#define Q
Definition sirandom.c:26

◆ nlDelete()

void nlDelete ( number * a,
const coeffs r )

Definition at line 2638 of file longrat.cc.

2639{
2640 if (*a!=NULL)
2641 {
2642 nlTest(*a, r);
2643 if ((SR_HDL(*a) & SR_INT)==0)
2644 {
2645 _nlDelete_NoImm(a);
2646 }
2647 *a=NULL;
2648 }
2649}
#define nlTest(a, r)
Definition longrat.cc:87
void _nlDelete_NoImm(number *a)
Definition longrat.cc:1742
#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 1614 of file longrat.cc.

1615{
1616 if (!(SR_HDL(n) & SR_INT))
1617 {
1618 if (n->s==0)
1619 {
1620 nlNormalize(n,r);
1621 }
1622 if (!(SR_HDL(n) & SR_INT))
1623 {
1624 if (n->s!=3)
1625 {
1626 number u=ALLOC_RNUMBER();
1627 u->s=3;
1628#if defined(LDEBUG)
1629 u->debug=123456;
1630#endif
1631 mpz_init_set(u->z,n->n);
1632 u=nlShort3_noinline(u);
1633 return u;
1634 }
1635 }
1636 }
1637 return INT_TO_SR(1);
1638}
#define ALLOC_RNUMBER()
Definition coeffs.h:94
number nlShort3_noinline(number x)
Definition longrat.cc:159
void nlNormalize(number &x, const coeffs r)
Definition longrat.cc:1482
#define INT_TO_SR(INT)
Definition longrat.h:68

◆ nlGetNumerator()

number nlGetNumerator ( number & n,
const coeffs r )

Definition at line 1643 of file longrat.cc.

1644{
1645 if (!(SR_HDL(n) & SR_INT))
1646 {
1647 if (n->s==0)
1648 {
1649 nlNormalize(n,r);
1650 }
1651 if (!(SR_HDL(n) & SR_INT))
1652 {
1653 number u=ALLOC_RNUMBER();
1654#if defined(LDEBUG)
1655 u->debug=123456;
1656#endif
1657 u->s=3;
1658 mpz_init_set(u->z,n->z);
1659 if (n->s!=3)
1660 {
1661 u=nlShort3_noinline(u);
1662 }
1663 return u;
1664 }
1665 }
1666 return n; // imm. int
1667}

◆ 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 2516 of file longrat.cc.

2517{
2518 number z=ALLOC_RNUMBER();
2519#if defined(LDEBUG)
2520 z->debug=123456;
2521#endif
2522 mpz_init_set_si(z->z,(long)i);
2523 mpz_init_set_si(z->n,(long)j);
2524 z->s = 0;
2525 nlNormalize(z,r);
2526 return z;
2527}
int j
Definition facHensel.cc:110

◆ 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 2529 of file longrat.cc.

2530{
2531 number z=ALLOC_RNUMBER();
2532#if defined(LDEBUG)
2533 z->debug=123456;
2534#endif
2535 mpz_init_set(z->z,i);
2536 mpz_init_set(z->n,j);
2537 z->s = 0;
2538 nlNormalize(z,r);
2539 return z;
2540}

◆ nlInitChar()

BOOLEAN nlInitChar ( coeffs r,
void * p )

Definition at line 3560 of file longrat.cc.

3561{
3562 r->is_domain=TRUE;
3563 r->rep=n_rep_gap_rat;
3564
3565 r->nCoeffIsEqual=nlCoeffIsEqual;
3566 //r->cfKillChar = ndKillChar; /* dummy */
3567 //r->cfCoeffString=nlCoeffString;
3568 r->cfCoeffName=nlCoeffName;
3569
3570 r->cfInitMPZ = nlInitMPZ;
3571 r->cfMPZ = nlMPZ;
3572
3573 r->cfMult = nlMult;
3574 r->cfSub = nlSub;
3575 r->cfAdd = nlAdd;
3576 r->cfExactDiv= nlExactDiv;
3577 if (p==NULL) /* Q */
3578 {
3579 r->is_field=TRUE;
3580 r->cfDiv = nlDiv;
3581 //r->cfGcd = ndGcd_dummy;
3582 r->cfSubringGcd = nlGcd;
3583 }
3584 else /* Z: coeffs_BIGINT */
3585 {
3586 r->is_field=FALSE;
3587 r->cfDiv = nlIntDiv;
3588 r->cfIntMod= nlIntMod;
3589 r->cfGcd = nlGcd;
3590 r->cfDivBy=nlDivBy;
3591 r->cfDivComp = nlDivComp;
3592 r->cfIsUnit = nlIsUnit;
3593 r->cfGetUnit = nlGetUnit;
3594 r->cfQuot1 = nlQuot1;
3595 r->cfLcm = nlLcm;
3596 r->cfXExtGcd=nlXExtGcd;
3597 r->cfQuotRem=nlQuotRem;
3598 }
3599 r->cfInit = nlInit;
3600 r->cfSize = nlSize;
3601 r->cfInt = nlInt;
3602
3603 r->cfChineseRemainder=nlChineseRemainderSym;
3604 r->cfFarey=nlFarey;
3605 r->cfInpNeg = nlNeg;
3606 r->cfInvers= nlInvers;
3607 r->cfCopy = nlCopy;
3608 r->cfRePart = nlCopy;
3609 //r->cfImPart = ndReturn0;
3610 r->cfWriteLong = nlWrite;
3611 r->cfRead = nlRead;
3612 r->cfNormalize=nlNormalize;
3613 r->cfGreater = nlGreater;
3614 r->cfEqual = nlEqual;
3615 r->cfIsZero = nlIsZero;
3616 r->cfIsOne = nlIsOne;
3617 r->cfIsMOne = nlIsMOne;
3618 r->cfGreaterZero = nlGreaterZero;
3619 r->cfPower = nlPower;
3620 r->cfGetDenom = nlGetDenom;
3621 r->cfGetNumerator = nlGetNumerator;
3622 r->cfExtGcd = nlExtGcd; // only for ring stuff and Z
3623 r->cfNormalizeHelper = nlNormalizeHelper;
3624 r->cfDelete= nlDelete;
3625 r->cfSetMap = nlSetMap;
3626 //r->cfName = ndName;
3627 r->cfInpMult=nlInpMult;
3628 r->cfInpAdd=nlInpAdd;
3629 //r->cfCoeffWrite=nlCoeffWrite;
3630
3631 r->cfClearContent = nlClearContent;
3632 r->cfClearDenominators = nlClearDenominators;
3633
3634#ifdef LDEBUG
3635 // debug stuff
3636 r->cfDBTest=nlDBTest;
3637#endif
3638 r->convSingNFactoryN=nlConvSingNFactoryN;
3639 r->convFactoryNSingN=nlConvFactoryNSingN;
3640
3641 r->cfRandom=nlRandom;
3642
3643 // io via ssi
3644 r->cfWriteFd=nlWriteFd;
3645 r->cfWriteFd_S=nlWriteFd_S;
3646 r->cfReadFd=nlReadFd;
3647 r->cfReadFd_S=nlReadFd_S;
3648
3649 //r->type = n_Q;
3650 r->ch = 0;
3651 r->has_simple_Alloc=FALSE;
3652 r->has_simple_Inverse=FALSE;
3653
3654 // variables for this type of coeffs:
3655 // (none)
3656 return FALSE;
3657}
#define TRUE
Definition auxiliary.h:101
@ n_rep_gap_rat
(number), see longrat.h
Definition coeffs.h:118
void nlWriteFd(number n, const ssiInfo *d, const coeffs)
Definition longrat.cc:3311
LINLINE void nlInpMult(number &a, number b, const coeffs r)
Definition longrat.cc:2757
LINLINE BOOLEAN nlEqual(number a, number b, const coeffs r)
Definition longrat.cc:2569
LINLINE number nlAdd(number la, number li, const coeffs r)
Definition longrat.cc:2673
long nlInt(number &n, const coeffs r)
Definition longrat.cc:741
static number nlLcm(number a, number b, const coeffs r)
Definition longrat.cc:3536
LINLINE number nlSub(number la, number li, const coeffs r)
Definition longrat.cc:2739
number nlIntMod(number a, number b, const coeffs r)
Definition longrat.cc:1017
LINLINE number nlCopy(number a, const coeffs r)
Definition longrat.cc:2625
LINLINE number nlNeg(number za, const coeffs r)
Definition longrat.cc:2654
number nlXExtGcd(number a, number b, number *s, number *t, number *u, number *v, const coeffs r)
Definition longrat.cc:2809
void nlPower(number x, int exp, number *lu, const coeffs r)
Definition longrat.cc:1251
number nlQuotRem(number a, number b, number *r, const coeffs R)
Definition longrat.cc:2861
number nlFarey(number nN, number nP, const coeffs CF)
Definition longrat.cc:2949
LINLINE BOOLEAN nlIsOne(number a, const coeffs r)
Definition longrat.cc:2596
number nlNormalizeHelper(number a, number b, const coeffs r)
Definition longrat.cc:1526
LINLINE void nlDelete(number *a, const coeffs r)
Definition longrat.cc:2638
BOOLEAN nlGreaterZero(number za, const coeffs r)
Definition longrat.cc:1304
LINLINE void nlInpAdd(number &a, number b, const coeffs r)
Definition longrat.cc:2691
number nlExactDiv(number a, number b, const coeffs r)
Definition longrat.cc:871
const char * nlRead(const char *s, number *a, const coeffs r)
Definition longrat0.cc:31
void nlMPZ(mpz_t m, number &n, const coeffs r)
get numerator as mpz_t
Definition longrat.cc:2791
number nlInvers(number a, const coeffs r)
Definition longrat.cc:791
BOOLEAN nlIsUnit(number a, const coeffs)
Definition longrat.cc:1132
static number nlConvFactoryNSingN(const CanonicalForm f, const coeffs r)
Definition longrat.cc:365
number nlChineseRemainderSym(number *x, number *q, int rl, BOOLEAN sym, CFArray &inv_cache, const coeffs CF)
Definition longrat.cc:3076
int nlDivComp(number a, number b, const coeffs r)
Definition longrat.cc:1092
char * nlCoeffName(const coeffs r)
Definition longrat.cc:3305
number nlExtGcd(number a, number b, number *s, number *t, const coeffs)
Definition longrat.cc:3020
LINLINE number nlMult(number a, number b, const coeffs r)
Definition longrat.cc:2709
static number nlInitMPZ(mpz_t m, const coeffs)
Definition longrat.cc:164
static void nlClearDenominators(ICoeffsEnumerator &numberCollectionEnumerator, number &c, const coeffs cf)
Definition longrat.cc:3211
LINLINE BOOLEAN nlIsZero(number za, const coeffs r)
Definition longrat.cc:2605
number nlGetDenom(number &n, const coeffs r)
Definition longrat.cc:1614
number nlGcd(number a, number b, const coeffs r)
Definition longrat.cc:1341
number nlReadFd(const ssiInfo *d, const coeffs)
Definition longrat.cc:3406
int nlSize(number a, const coeffs)
Definition longrat.cc:712
nMapFunc nlSetMap(const coeffs src, const coeffs dst)
Definition longrat.cc:2454
BOOLEAN nlDBTest(number a, const char *f, const int l)
number nlDiv(number a, number b, const coeffs r)
Definition longrat.cc:1141
BOOLEAN nlIsMOne(number a, const coeffs r)
Definition longrat.cc:1329
static void nlClearContent(ICoeffsEnumerator &numberCollectionEnumerator, number &c, const coeffs cf)
Definition longrat.cc:3120
number nlGetNumerator(number &n, const coeffs r)
Definition longrat.cc:1643
BOOLEAN nlCoeffIsEqual(const coeffs r, n_coeffType n, void *p)
Definition longrat.cc:3524
static CanonicalForm nlConvSingNFactoryN(number n, const BOOLEAN setChar, const coeffs)
Definition longrat.cc:327
number nlGetUnit(number n, const coeffs cf)
Definition longrat.cc:1103
coeffs nlQuot1(number c, const coeffs r)
Definition longrat.cc:1109
number nlReadFd_S(char **s, const coeffs)
Definition longrat.cc:3465
BOOLEAN nlGreater(number a, number b, const coeffs r)
Definition longrat.cc:1314
BOOLEAN nlDivBy(number a, number b, const coeffs)
Definition longrat.cc:1078
static void nlWriteFd_S(number n, const coeffs)
Definition longrat.cc:3357
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:3546

◆ nlInpGcd()

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

Definition at line 2914 of file longrat.cc.

2915{
2916 if ((SR_HDL(b)|SR_HDL(a))&SR_INT)
2917 {
2918 number n=nlGcd(a,b,r);
2919 nlDelete(&a,r);
2920 a=n;
2921 }
2922 else
2923 {
2924 mpz_gcd(a->z,a->z,b->z);
2925 a=nlShort3_noinline(a);
2926 }
2927}
CanonicalForm b
Definition cfModGcd.cc:4111

◆ nlIsInteger()

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

Definition at line 94 of file longrat.h.

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

◆ nlModP()

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

Definition at line 1573 of file longrat.cc.

1574{
1575 const int p = n_GetChar(Zp);
1576 assume( p > 0 );
1577
1578 const long P = p;
1579 assume( P > 0 );
1580
1581 // embedded long within q => only long numerator has to be converted
1582 // to int (modulo char.)
1583 if (SR_HDL(q) & SR_INT)
1584 {
1585 long i = SR_TO_INT(q);
1586 return n_Init( i, Zp );
1587 }
1588
1589 const unsigned long PP = p;
1590
1591 // numerator modulo char. should fit into int
1592 number z = n_Init( static_cast<long>(mpz_fdiv_ui(q->z, PP)), Zp );
1593
1594 // denominator != 1?
1595 if (q->s!=3)
1596 {
1597 // denominator modulo char. should fit into int
1598 number n = n_Init( static_cast<long>(mpz_fdiv_ui(q->n, PP)), Zp );
1599
1600 number res = n_Div( z, n, Zp );
1601
1602 n_Delete(&z, Zp);
1603 n_Delete(&n, Zp);
1604
1605 return res;
1606 }
1607
1608 return z;
1609}
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:618
static FORCE_INLINE int n_GetChar(const coeffs r)
Return the characteristic of the coeff. domain.
Definition coeffs.h:450
static FORCE_INLINE void n_Delete(number *p, const coeffs r)
delete 'p'
Definition coeffs.h:461
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:541
CanonicalForm res
Definition facAbsFact.cc:60
#define SR_TO_INT(SR)
Definition longrat.h:69

◆ nlMPZ()

void nlMPZ ( mpz_t m,
number & n,
const coeffs r )

get numerator as mpz_t

Definition at line 2791 of file longrat.cc.

2792{
2793 nlTest(n, r);
2794 nlNormalize(n, r);
2795 if (SR_HDL(n) & SR_INT) mpz_init_set_si(m, SR_TO_INT(n)); /* n fits in an int */
2796 else mpz_init_set(m, (mpz_ptr)n->z);
2797}
int m
Definition cfEzgcd.cc:128

◆ nlMPZ2()

void nlMPZ2 ( mpz_t m,
number & n,
const coeffs r )

get demoninator as mpz_t

Definition at line 2799 of file longrat.cc.

2800{
2801 nlTest(n, r);
2802 nlNormalize(n, r);
2803 if (SR_HDL(n) & SR_INT) mpz_init_set_si(m,1); /* small int*/
2804 else if (n->s==3) mpz_init_set_si(m,1); /* large int*/
2805 else mpz_init_set(m, (mpz_ptr)n->n);
2806}

◆ nlNormalize()

void nlNormalize ( number & x,
const coeffs r )

Definition at line 1482 of file longrat.cc.

1483{
1484 if ((SR_HDL(x) & SR_INT) ||(x==NULL))
1485 return;
1486 if (x->s==3)
1487 {
1489 nlTest(x,r);
1490 return;
1491 }
1492 else if (x->s==0)
1493 {
1494 if (mpz_cmp_si(x->n,1L)==0)
1495 {
1496 mpz_clear(x->n);
1497 x->s=3;
1498 x=nlShort3(x);
1499 }
1500 else
1501 {
1502 mpz_t gcd;
1503 mpz_init(gcd);
1504 mpz_gcd(gcd,x->z,x->n);
1505 x->s=1;
1506 if (mpz_cmp_si(gcd,1L)!=0)
1507 {
1508 mpz_divexact(x->z,x->z,gcd);
1509 mpz_divexact(x->n,x->n,gcd);
1510 if (mpz_cmp_si(x->n,1L)==0)
1511 {
1512 mpz_clear(x->n);
1513 x->s=3;
1515 }
1516 }
1517 mpz_clear(gcd);
1518 }
1519 }
1520 nlTest(x, r);
1521}
static number nlShort3(number x)
Definition longrat.cc:109
int gcd(int a, int b)

◆ nlQlogSize()

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

only used by slimgb (tgb.cc)

Definition at line 76 of file longrat.h.

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