Changeset c879ee in git


Ignore:
Timestamp:
Oct 19, 2012, 6:38:54 PM (11 years ago)
Author:
Oleksandr Motsak <motsak@…>
Branches:
(u'jengelh-datetime', 'ceac47cbc86fe4a15902392bdbb9bd2ae0ea02c6')(u'spielwiese', '00e2e9c41af3fde1273eb3633f4c0c7c3db2579d')
Children:
05fd55e34baa83465ce4306966c9011d1a156232
Parents:
1bc7201c1a771fb5cc842ca4f475ba3ea91e697963e72b40a6237e50811b0e8745201177d25cb979
Message:
Merge pull request #193 from mmklee/64bitIntegersFactorySW

64bit integers factory sw
Files:
35 edited

Legend:

Unmodified
Added
Removed
  • Tst/Old/m17ex.res.gz.uu

    r1bc7201 rc879ee  
    1 begin 640 m17ex.res.gz
    2 M'XL("(8/CDP``VTQ-V5X+G)E<P"-4CU/PS`0W?,K3A5#OAIJ)TU3JC`@EDJ(
    3 MI=U002%-BJ625K$K^?CUG)O4*0P(#_;9?N_=O=.MUH_+9P!@][2UHME!"_DD
    4 M='6(7K@]+IQ5#^`&<#SL$6K(8:Y9.F:99C'R,5TXQ@$=$TS.KPQY$*<ZP\3R
    5 MXPCL"@@SPZF!3C$E8MKQ8DQ)C.,LF&,VI$Y,ZMM;DQ9\<#41D7NO_'Q)QUR;
    6 M(I@V-6#B6=K49*R+4AU:\56YM;=P7MCFSJ'7-PKR>1?Q36Y%>HWN(][D8ST-
    7 MD#N$.=-8R$)N]=.^K+92I[:1?2H)1;.%S]->B>->E$*)2H9@2;.H(]6BE:JG
    8 M@"`2E(=&JJ)1D<5FT:7E._+N8A+HS/-=S:DF;VC/_/Z'S]UOGVSP:9C6G,Z,
    9 MU6MO[*+))KVW]4<%LOBL0#10?A1MJ:I62"5*X'<6S**KV>%7LT,"OD_]V5:U
    10 M:+I_W[>T8:+^LL?B_]L+<#!'*E?>>&@GD=$X/2T?8*2DBO;B?;2@X(U:KT[2
    11 .9=[BQOD&`C*U1A0#````
     1begin 644 m17ex.res.gz
     2M'XL("-SF^D\``VTQ-V5X+G)E<P"-4DM/PD`0OO=73(B'OJCLMI0BJ0?CA<1X
     3M@9M!4TN+FV`AW279\=<[2\L6/1A[V.[C>\PWF=7Z<?D,`.R>EE8T.V@AGX2N
     4M#M$+M\>%L^H!W`".ASU"#3G,-4O'+-,L1CZF`\<XH-\$D_,M0Q[$J<XPL?PX
     5M`OL%A)GAU$"GF!(Q[7@QIB3&<1;,,1NL$V-]>VMLP0=7$Q&Y]\K/AW3,M2F"
     6M:5,#)IZE38UC793JT(JORJV]A?/"-G<.W;[1)I]W.[[)K4BOT3W$FWRLIP%R
     7MAS!G&@M9R*U^VI?55NK4-K*WDE`T6_@\[94X[D4IE*AD")8TBSI2+5JI>@H(
     8M(D%Y:*0J&A59;!9=6KZC["XF@<X\W]6<:O*&]LSO?^3<_<[)AIR&:</IS$2]
     9MSL8NFFS29UM_5""+SPI$`^5'T9)+U0JI1`G\SJ)9=#4\_&IX2,'WJ4';JA9-
     10M]^[[EC:,U%_Y6/S_?`$.Z4CE*AP/[2@RFJ>GY0.,E%317KR/%K1YH]ZKDW29
     11-M[AQO@%*)IX/%0,`````
    1212`
    1313end
  • Tst/Old/m17ex.stat

    r1bc7201 rc879ee  
    1 1 >> tst_memory_0 :: 1284378480:3115- 13145 :3-1-1:ix86-Linux:mamawutz:171372 1292524760:3120- 13145 :3-1-2:ix86-Linux:mamawutz:171636
    2 1 >> tst_memory_1 :: 1284378480:3115- 13145 :3-1-1:ix86-Linux:mamawutz:667288 1292524760:3120- 13145 :3-1-2:ix86-Linux:mamawutz:667336
    3 1 >> tst_memory_2 :: 1284378480:3115- 13145 :3-1-1:ix86-Linux:mamawutz:700072 1292524760:3120- 13145 :3-1-2:ix86-Linux:mamawutz:700120
    4 1 >> tst_timer_1 :: 1284378480:3115- 13145 :3-1-1:ix86-Linux:mamawutz:5 1292524760:3120- 13145 :3-1-2:ix86-Linux:mamawutz:5
     11 >> tst_memory_0 :: 1341843164:3144- exported :3-1-4:ix86-Linux:mamawutz:180696
     21 >> tst_memory_1 :: 1341843164:3144- exported :3-1-4:ix86-Linux:mamawutz:2240284
     31 >> tst_memory_2 :: 1341843164:3144- exported :3-1-4:ix86-Linux:mamawutz:2273068
     41 >> tst_timer_1 :: 1341843164:3144- exported :3-1-4:ix86-Linux:mamawutz:2
  • Tst/Old/m17ex.tst

    r1bc7201 rc879ee  
    88  poly g = (y4+x8)*(x2+y2);
    99  factorize(g);
    10   // The same in charcteristic 2:
     10  // The same in characteristic 2:
    1111  ring r =2,(x,y),dp;
    1212  poly g = (y4+x8)*(x2+y2);
  • factory/FLINTconvert.cc

    r1bc7201 rc879ee  
    140140    ulong coeff= nmod_poly_get_coeff_ui (poly, i);
    141141    if (!coeff == 0)
    142       result += CanonicalForm (coeff)*power (x,i);
     142      result += CanonicalForm ((long)coeff)*power (x,i);
    143143  }
    144144  return result;
  • factory/README

    r1bc7201 rc879ee  
    338338continuation):
    339339
    340   g++ -c /usr/local/include/templates/ftmpl_inst.cc \
    341     -fno-implicit-templates -O2 -fomit-frame-pointer -o ftmpl_inst.o
    342   g++ -c application.cc -fno-implicit-templates -O2 -fomit-frame-pointer \
    343     ftmpl_inst.o -lcf -lcfmem -lm -lgmp
     340  g++ -c /usr/local/include/templates/ftmpl_inst.cc -fno-implicit-templates -O2 -fomit-frame-pointer -o ftmpl_inst.o
     341  g++ -c application.cc -fno-implicit-templates -O2 -fomit-frame-pointer ftmpl_inst.o -lcf -lcfmem -lm -lgmp
    344342
    345343  This should work fine provided that you installed Factory in a location
  • factory/algext.cc

    r63e72b4 rc879ee  
    548548        return;
    549549      m *= (x - alpha);
    550       if(gnew == gm) // gnew did not change
    551       {
    552         cf = tryvcontent(gm, Variable(2), M, fail);
     550      if((firstLC(gnew) == gamma) || (gnew == gm)) // gnew did not change
     551      {
     552        cf = tryvcontent(gnew, Variable(2), M, fail);
    553553        if(fail)
    554554          return;
    555555        divides = true;
    556         g_image= gm;
     556        g_image= gnew;
    557557        g_image.tryDiv (cf, M, fail);
    558558        if(fail)
     
    692692  }
    693693  // here: a is the biggest alg. var in f and g AND some of f,g is in extension
    694   // (in the sequel b is used to swap alg/poly vars)
    695694  setReduce(a,false); // do not reduce expressions modulo mipo
    696695  tmp = getMipo(a);
     
    703702    mv = i;
    704703  // here: mv is level of the largest variable in f, g
    705   b = Variable(mv+1);
    706704  bound = new int[mv+1]; // 'bound' could be indexed from 0 to mv, but we will only use from 1 to mv
    707705  other = new int[mv+1];
     
    750748    if(isEqual(bound, other, 1, mv)) // equal
    751749    {
    752       chineseRemainder( D, q, replacevar( mapinto(Dp), a, b ), p, tmp, newq );
     750      chineseRemainder( D, q, mapinto(Dp), p, tmp, newq );
    753751      // tmp = Dp mod p
    754752      // tmp = D mod q
     
    758756        D = tmp;
    759757      On( SW_RATIONAL );
    760       tmp = replacevar( Farey( D, q ), b, a ); // Farey and switch back to alg var
     758      tmp = Farey( D, q ); // Farey
     759      tmp *= bCommonDen (tmp);
    761760      setReduce(a,true); // reduce expressions modulo mipo
    762761      On( SW_RATIONAL ); // needed by fdivides
     
    780779    // here: isLess(other, bound, 1, mv) ) ==> all previous primes unlucky
    781780    q = p;
    782     D = replacevar( mapinto(Dp), a, b ); // shortcut CRA // shortcut CRA
     781    D = mapinto(Dp); // shortcut CRA // shortcut CRA
    783782    for(int i=1; i<=mv; i++) // tighten bound
    784783      bound[i] = other[i];
  • factory/canonicalform.cc

    r1bc7201 rc879ee  
    217217
    218218//{{{ conversion functions
    219 int
     219long
    220220CanonicalForm::intval() const
    221221{
     
    13031303    if ( is_imm( value ) ) {
    13041304        ASSERT( is_imm( value ) == INTMARK, "sqrt() not implemented" );
    1305         int n = imm2int( value );
     1305        long n = imm2int( value );
    13061306        ASSERT( n >= 0, "arg to sqrt() less than zero" );
    13071307        if ( n == 0 || n == 1 )
    13081308            return CanonicalForm( n );
    13091309        else {
    1310             int x, y = n;
     1310            long x, y = n;
    13111311            do {
    13121312                x = y;
    13131313                // the intermediate result may not fit into an
    13141314                // integer, but the result does
    1315                 y = (unsigned int)(x + n/x)/2;
     1315                y = (unsigned long)(x + n/x)/2;
    13161316            } while ( y < x );
    13171317            return CanonicalForm( x );
     
    13401340    {
    13411341        ASSERT( is_imm( value ) == INTMARK, "ilog2() not implemented" );
    1342         int a = imm2int( value );
     1342        long a = imm2int( value );
    13431343        ASSERT( a > 0, "arg to ilog2() less or equal zero" );
    13441344        int n = -1;
     
    15841584            // calculate gcd using standard integer
    15851585            // arithmetic
    1586             int fInt = imm2int( f.value );
    1587             int gInt = imm2int( g.value );
     1586            long fInt = imm2int( f.value );
     1587            long gInt = imm2int( g.value );
    15881588
    15891589            if ( fInt < 0 ) fInt = -fInt;
     
    15921592            if ( gInt > fInt )
    15931593            {
    1594                 int swap = gInt;
     1594                long swap = gInt;
    15951595                gInt = fInt;
    15961596                fInt = swap;
     
    16011601            {
    16021602                // calculate (fInt, gInt) = (gInt, fInt%gInt)
    1603                 int r = fInt % gInt;
     1603                long r = fInt % gInt;
    16041604                fInt = gInt;
    16051605                gInt = r;
     
    16581658            // calculate extended gcd using standard integer
    16591659            // arithmetic
    1660             int fInt = imm2int( f.value );
    1661             int gInt = imm2int( g.value );
     1660            long fInt = imm2int( f.value );
     1661            long gInt = imm2int( g.value );
    16621662
    16631663            // to avoid any system dpendencies with `%', we work
     
    16681668            // swap fInt and gInt
    16691669            if ( gInt > fInt ) {
    1670                 int swap = gInt;
     1670                long swap = gInt;
    16711671                gInt = fInt;
    16721672                fInt = swap;
    16731673            }
    16741674
    1675             int u = 1; int v = 0;
    1676             int uNext = 0; int vNext = 1;
     1675            long u = 1; long v = 0;
     1676            long uNext = 0; long vNext = 1;
    16771677
    16781678            // at any step, we have:
     
    16821682            // and gInt, resp., at the beginning
    16831683            while ( gInt ) {
    1684                 int r = fInt % gInt;
    1685                 int q = fInt / gInt;
    1686                 int uSwap = u - q * uNext;
    1687                 int vSwap = v - q * vNext;
     1684                long r = fInt % gInt;
     1685                long q = fInt / gInt;
     1686                long uSwap = u - q * uNext;
     1687                long vSwap = v - q * vNext;
    16881688
    16891689                // update variables
     
    16951695
    16961696            // now, assign to a and b
    1697             int fTest = imm2int( f.value );
    1698             int gTest = imm2int( g.value );
     1697            long fTest = imm2int( f.value );
     1698            long gTest = imm2int( g.value );
    16991699            if ( gTest > fTest ) {
    17001700                a = v; b = u;
     
    18041804    int what = is_imm( value );
    18051805    if ( what == FFMARK )
    1806         return CanonicalForm( CFFactory::basic( FiniteFieldDomain, 0 ) );
     1806        return CanonicalForm( CFFactory::basic( FiniteFieldDomain, 0L ) );
    18071807    else  if ( what == GFMARK )
    1808         return CanonicalForm( CFFactory::basic( GaloisFieldDomain, 0 ) );
     1808        return CanonicalForm( CFFactory::basic( GaloisFieldDomain, 0L ) );
    18091809    else  if ( what )
    1810         return CanonicalForm( CFFactory::basic( IntegerDomain, 0 ) );
     1810        return CanonicalForm( CFFactory::basic( IntegerDomain, 0L ) );
    18111811    else
    18121812        return CanonicalForm( value->genZero() );
     
    18181818    int what = is_imm( value );
    18191819    if ( what == FFMARK )
    1820         return CanonicalForm( CFFactory::basic( FiniteFieldDomain, 1 ) );
     1820        return CanonicalForm( CFFactory::basic( FiniteFieldDomain, 1L ) );
    18211821    else  if ( what == GFMARK )
    1822         return CanonicalForm( CFFactory::basic( GaloisFieldDomain, 1 ) );
     1822        return CanonicalForm( CFFactory::basic( GaloisFieldDomain, 1L ) );
    18231823    else  if ( what )
    1824         return CanonicalForm( CFFactory::basic( IntegerDomain, 1 ) );
     1824        return CanonicalForm( CFFactory::basic( IntegerDomain, 1L ) );
    18251825    else
    18261826        return CanonicalForm( value->genOne() );
  • factory/canonicalform.h

    r1bc7201 rc879ee  
    6969    CF_INLINE CanonicalForm( InternalCF* );
    7070    CF_INLINE CanonicalForm( const int );
     71    CF_INLINE CanonicalForm( const long );
    7172    CF_INLINE CanonicalForm( const Variable & );
    7273    CF_INLINE CanonicalForm( const Variable &, int );
     
    100101
    101102    // conversion functions
    102     int intval() const;
     103    long intval() const;
    103104    CanonicalForm mapinto () const;
    104105
     
    123124    // assignment operators
    124125    CF_NO_INLINE CanonicalForm& operator = ( const CanonicalForm& );
    125     CF_NO_INLINE CanonicalForm& operator = ( const int );
     126    CF_NO_INLINE CanonicalForm& operator = ( const long );
    126127
    127128    CanonicalForm& operator += ( const CanonicalForm& );
  • factory/cf_chinese.cc

    r63e72b4 rc879ee  
    227227          }
    228228          else
     229            result += power( x, i.exp() ) * Farey(c,q);
     230#else
     231          if (c.inZ())
     232            result += power( x, i.exp() ) * Farey_n(c,q);
     233          else
     234            result += power( x, i.exp() ) * Farey(c,q);
    229235#endif
    230             result += power( x, i.exp() ) * Farey_n(c,q);
    231236        }
    232237        else
  • factory/cf_factor.cc

    r1bc7201 rc879ee  
    8989}
    9090
    91 #if 0
     91#if 1
    9292//#ifndef NOSTREAMIO
    9393void out_cf(const char *s1,const CanonicalForm &f,const char *s2)
  • factory/cf_factory.cc

    r1bc7201 rc879ee  
    2525
    2626InternalCF *
    27 CFFactory::basic ( int value )
     27CFFactory::basic ( long value )
    2828{
    2929    if ( currenttype == IntegerDomain )
     
    5050
    5151InternalCF *
    52 CFFactory::basic ( int type, int value )
     52CFFactory::basic ( int type, long value )
    5353{
    5454    if ( type == IntegerDomain )
     
    204204
    205205InternalCF *
    206 CFFactory::basic ( int type, int value, bool nonimm )
     206CFFactory::basic ( int type, long value, bool nonimm )
    207207{
    208208    if ( nonimm )
     
    231231
    232232InternalCF *
    233 CFFactory::rational ( int num, int den )
     233CFFactory::rational ( long num, long den )
    234234{
    235235    InternalRational * res = new InternalRational( num, den );
  • factory/cf_factory.h

    r1bc7201 rc879ee  
    2121    static int gettype () { return currenttype; }
    2222    static void settype ( int type );
    23     static InternalCF * basic ( int value );
    24     static InternalCF * basic ( int type, int value );
     23    static InternalCF * basic ( long value );
     24    static InternalCF * basic ( int type, long value );
    2525    static InternalCF * basic ( const char * str );
    2626    static InternalCF * basic ( const char * str, int base );
    2727    static InternalCF * basic ( int type, const char * const str );
    28     static InternalCF * basic ( int type, int value, bool nonimm );
     28    static InternalCF * basic ( int type, long value, bool nonimm );
    2929    static InternalCF * basic ( const mpz_ptr num );
    30     static InternalCF * rational ( int num, int den );
     30    static InternalCF * rational ( long num, long den );
    3131    static InternalCF * rational ( const mpz_ptr num, const mpz_ptr den, bool normalize );
    3232    static InternalCF * poly ( const Variable & v, int exp, const CanonicalForm & c );
  • factory/cf_gcd_smallp.cc

    r63e72b4 rc879ee  
    42294229  Evaluation result= Evaluation (A.min(), A.max());
    42304230  ASSERT (A.min() == 2, "expected A.min() == 2");
    4231   ASSERT (A.max() >= n, "expected A.max() >= n");
    42324231  int max_deg;
    42334232  int k= n;
  • factory/cf_inline.cc

    r1bc7201 rc879ee  
    121121CF_INLINE
    122122CanonicalForm::CanonicalForm ()
    123     : value( CFFactory::basic( (int)0 ) )
     123    : value( CFFactory::basic( (long)0 ) )
    124124{
    125125}
     
    140140CF_INLINE
    141141CanonicalForm::CanonicalForm ( const int i )
     142    : value( CFFactory::basic( (long)i ) )
     143{
     144}
     145
     146CF_INLINE
     147CanonicalForm::CanonicalForm ( const long i )
    142148    : value( CFFactory::basic( i ) )
    143149{
     
    300306//}}}
    301307CF_INLINE CanonicalForm &
    302 CanonicalForm::operator = ( const int cf )
     308CanonicalForm::operator = ( const long cf )
    303309{
    304310    if ( (! is_imm( value )) && value->deleteObject() )
  • factory/facFqBivarUtil.cc

    r63e72b4 rc879ee  
    519519  }
    520520
    521   q= newtonDiv (bufF, G, xToLOldL);
     521  if (l-oldL > 0)
     522    q= newtonDiv (bufF, G, xToLOldL);
     523  else
     524    q= 0;
    522525  q *= xToOldL;
    523526  q += oldQ;
  • factory/facFqSquarefree.h

    r63e72b4 rc879ee  
    1818#include "cf_factory.h"
    1919#include "fac_sqrfree.h"
     20#include "cf_factory.h"
    2021
    2122/// squarefree factorization over a finite field
  • factory/facHensel.cc

    r63e72b4 rc879ee  
    544544  }
    545545
     546  setReduce (alpha, false);
    546547  for (k= 0; k < factors.length(); k++)
    547548  {
     
    554555    }
    555556  }
     557  setReduce (alpha, true);
    556558  setCharacteristic(0);
    557559
     
    591593  }
    592594  setCharacteristic (p);
     595  setReduce (alpha, false);
    593596  recResult= mapinto (recResult);
     597  setReduce (alpha, true);
    594598  if (mipoHasDen)
    595599  {
     
    606610    coeffE= div (e, modulus);
    607611    setCharacteristic (p);
     612    if (mipoHasDen)
     613      setReduce (gamma, false);
     614    else
     615      setReduce (alpha, false);
    608616    coeffE= coeffE.mapinto();
     617    if (mipoHasDen)
     618      setReduce (gamma, true);
     619    else
     620      setReduce (alpha, true);
    609621    if (mipoHasDen)
    610622      coeffE= replacevar (coeffE, gamma, beta);
     
    619631      {
    620632        setCharacteristic (p);
     633        setReduce (alpha, false);
    621634        g= mulNTL (coeffE, j.getItem());
    622635        g= modNTL (g, bufFactors[ii]);
     636        setReduce (alpha, true);
    623637        setCharacteristic (0);
    624638        if (mipoHasDen)
    625639        {
     640          setReduce (beta, false);
    626641          k.getItem() += replacevar (g.mapinto()*modulus, beta, gamma);
    627642          e -= mulNTL (replacevar (g.mapinto(), beta, gamma)*modulus,
    628643                                   l.getItem(), b);
     644          setReduce (beta, true);
    629645        }
    630646        else
  • factory/facMul.cc

    r63e72b4 rc879ee  
    404404      {
    405405        ZZ_p::init (convertFacCF2NTLZZ (b.getpk()));
    406         ZZ_pX NTLmipo= to_ZZ_pX (convertFacCF2NTLZZX (getMipo (alpha)));
     406        CanonicalForm mipo= getMipo (alpha);
     407        bool is_rat= isOn (SW_RATIONAL);
     408        if (!is_rat)
     409          On (SW_RATIONAL);
     410        mipo *=bCommonDen (mipo);
     411        if (!is_rat)
     412          Off (SW_RATIONAL);
     413        ZZ_pX NTLmipo= to_ZZ_pX (convertFacCF2NTLZZX (mipo));
    407414        ZZ_pE::init (NTLmipo);
    408415        ZZ_pEX NTLg= convertFacCF2NTLZZ_pEX (G, NTLmipo);
  • factory/fac_ezgcd.cc

    r63e72b4 rc879ee  
    215215  Evaluation result= Evaluation (A.min(), A.max());
    216216  ASSERT (A.min() == 2, "expected A.min() == 2");
    217   ASSERT (A.max() == n, "expected A.max() == n");
    218217  int max_deg;
    219218  int k= n;
  • factory/ffops.h

    r1bc7201 rc879ee  
    3737}
    3838
     39inline long ff_norm ( const long a )
     40{
     41    long n = a % ff_prime;
     42#if defined(i386) || defined(NTL_AVOID_BRANCHING)
     43    n += (n >> 31) & ff_prime;
     44    return n;
     45#else
     46    if (n < 0) n += ff_prime;
     47    return n;
     48#endif
     49}
     50
    3951inline int ff_symmetric( const int a )
     52{
     53    if ( cf_glob_switches.isOn( SW_SYMMETRIC_FF ) )
     54        return ( a > ff_halfprime ) ? a - ff_prime : a;
     55    else
     56        return a;
     57}
     58
     59inline long ff_symmetric( const long a )
    4060{
    4161    if ( cf_glob_switches.isOn( SW_SYMMETRIC_FF ) )
  • factory/gfops.cc

    r1bc7201 rc879ee  
    222222}
    223223
     224long gf_gf2ff ( long a )
     225{
     226    if ( gf_iszero( a ) )
     227        return 0;
     228    else
     229    {
     230        // starting from z^0=1, step through the table
     231        // counting the steps until we hit z^a or z^0
     232        // again.  since we are working in char(p), the
     233        // latter is guaranteed to be fulfilled.
     234        long i = 0, ff = 1;
     235        do
     236        {
     237            if ( i == a )
     238                return ff;
     239            ff++;
     240            i = gf_table[i];
     241        } while ( i != 0 );
     242        return -1;
     243    }
     244}
     245
    224246int gf_gf2ff ( int a )
    225247{
     
    244266}
    245267
    246 bool gf_isff ( int a )
     268bool gf_isff ( long a )
    247269{
    248270    if ( gf_iszero( a ) )
     
    254276    }
    255277}
     278
     279bool gf_isff ( int a )
     280{
     281    if ( gf_iszero( a ) )
     282        return true;
     283    else
     284    {
     285        // z^a in GF(p) iff (z^a)^p-1=1
     286        return gf_isone( gf_power( a, gf_p - 1 ) );
     287    }
     288}
  • factory/gfops.h

    r1bc7201 rc879ee  
    3838}
    3939
     40inline bool gf_iszero ( long a )
     41{
     42    return gf_q == a;
     43}
     44
    4045inline bool gf_isone ( int a )
     46{
     47    return 0 == a;
     48}
     49
     50inline bool gf_isone ( long a )
    4151{
    4252    return 0 == a;
     
    5464        return gf_q;
    5565    int c = 0;
     66    while ( i > 1 ) {
     67        c = gf_table[c];
     68        i--;
     69    }
     70    return c;
     71}
     72
     73inline long gf_int2gf ( long i )
     74{
     75    while ( i < 0 )
     76        i += gf_p;
     77    while ( i >= gf_p )
     78        i -= gf_p;
     79    if ( i == 0 )
     80        return gf_q;
     81    long c = 0;
    5682    while ( i > 1 ) {
    5783        c = gf_table[c];
     
    138164}
    139165
     166inline long gf_mul ( long a, int b )
     167{
     168    if ( a == gf_q || b == gf_q )
     169        return gf_q;
     170    else {
     171        long i = a + b;
     172        if ( i >= gf_q1 ) i -= gf_q1;
     173        return i;
     174    }
     175}
     176
    140177inline int gf_div ( int a, int b )
    141178{
     
    184221        return gf_mul( a, gf_power( a, n-1 ) );
    185222}
     223
     224inline long gf_power ( long a, int n )
     225{
     226    if ( n == 0 )
     227        return 0;
     228    else if ( n == 1 )
     229        return a;
     230    else
     231        return gf_mul( a, gf_power( a, n-1 ) );
     232}
    186233//}}}
    187234
     
    191238/*BEGINPUBLIC*/
    192239
     240long gf_gf2ff ( long a );
    193241int gf_gf2ff ( int a );
    194242
     243bool gf_isff ( long a );
    195244bool gf_isff ( int a );
    196245
  • factory/imm.h

    r1bc7201 rc879ee  
    2626#include "int_cf.h"
    2727
    28 const int INTMARK = 1;
    29 const int FFMARK = 2;
    30 const int GFMARK = 3;
     28const long INTMARK = 1;
     29const long FFMARK = 2;
     30const long GFMARK = 3;
    3131
    3232/* define type of your compilers 64 bit integer type */
     
    3535#endif
    3636
    37 const int MINIMMEDIATE = -268435454; // -2^28-2
    38 const int MAXIMMEDIATE = 268435454;  // 2^28-2
     37#if SIZEOF_LONG == 4
     38const long MINIMMEDIATE = -268435454; // -2^28-2
     39const long MAXIMMEDIATE = 268435454;  // 2^28-2
     40#else
     41const long MINIMMEDIATE = -(1L<<60)+2L; // -2^60-2
     42const long MAXIMMEDIATE = (1L<<60)-2L;  // 2^60-2
     43#endif
     44
    3945#if defined(WINNT) && ! defined(__GNUC__)
    4046const INT64 MINIMMEDIATELL = -268435454i64;
     
    4955#if 1
    5056
    51 inline int imm2int ( const InternalCF * const imm )
    52 {
    53     return ((int)((long)imm)) >> 2;
    54 }
    55 
    56 inline InternalCF * int2imm ( int i )
     57inline long imm2int ( const InternalCF * const imm )
     58{
     59    return ((long)imm) >> 2;
     60}
     61
     62inline InternalCF * int2imm ( long i )
    5763{
    5864    return (InternalCF*)(long)((i << 2) | INTMARK );
     
    7076}
    7177
    72 inline InternalCF * int2imm ( int i )
     78inline InternalCF * int2imm ( long i )
    7379{
    7480    if ( i < 0 )
     
    8086#endif
    8187
    82 inline InternalCF * int2imm_p ( int i )
     88inline InternalCF * int2imm_p ( long i )
    8389{
    8490    return (InternalCF*)(long)((i << 2) | FFMARK );
    8591}
    8692
    87 inline InternalCF * int2imm_gf ( int i )
     93inline InternalCF * int2imm_gf ( long i )
    8894{
    8995    return (InternalCF*)(long)((i << 2) | GFMARK );
     
    143149
    144150//{{{ conversion functions
    145 inline int imm_intval ( const InternalCF* const op )
     151inline long imm_intval ( const InternalCF* const op )
    146152{
    147153    if ( is_imm( op ) == FFMARK )
     
    253259inline InternalCF * imm_add ( const InternalCF * const lhs, const InternalCF * const rhs )
    254260{
    255     int result = imm2int( lhs ) + imm2int( rhs );
     261    long result = imm2int( lhs ) + imm2int( rhs );
    256262    if ( ( result > MAXIMMEDIATE ) || ( result < MINIMMEDIATE ) )
    257263        return CFFactory::basic( result );
     
    272278inline InternalCF * imm_sub ( const InternalCF * const lhs, const InternalCF * const rhs )
    273279{
    274     int result = imm2int( lhs ) - imm2int( rhs );
     280    long result = imm2int( lhs ) - imm2int( rhs );
    275281    if ( ( result > MAXIMMEDIATE ) || ( result < MINIMMEDIATE ) )
    276282        return CFFactory::basic( result );
     
    292298imm_mul ( InternalCF * lhs, InternalCF * rhs )
    293299{
    294     INT64 result = (INT64)imm2int( lhs ) * imm2int( rhs );
    295     if ( ( result > MAXIMMEDIATELL ) || ( result < MINIMMEDIATELL ) ) {
    296         InternalCF * res = CFFactory::basic( IntegerDomain, imm2int( lhs ), true );
     300    long a = imm2int( lhs );
     301    long b = imm2int( rhs );
     302    INT64 result = (INT64)a * (INT64)b;
     303    if ( ( a!=0L ) && ((result/a!=b)
     304      ||(result>MAXIMMEDIATE)||(result<MINIMMEDIATE) ) )
     305    {
     306        InternalCF * res = CFFactory::basic( IntegerDomain, a, true );
    297307        return res->mulcoeff( rhs );
    298308    }
    299309    else
    300         return int2imm( (int)result );
     310        return int2imm( result );
    301311}
    302312
     
    313323inline InternalCF * imm_div ( const InternalCF * const lhs, const InternalCF * const rhs )
    314324{
    315     int a = imm2int( lhs );
    316     int b = imm2int( rhs );
     325    long a = imm2int( lhs );
     326    long b = imm2int( rhs );
    317327    if ( a > 0 )
    318328        return int2imm( a / b );
     
    328338        return CFFactory::rational( imm2int( lhs ), imm2int( rhs ) );
    329339    else {
    330         int a = imm2int( lhs );
    331         int b = imm2int( rhs );
     340        long a = imm2int( lhs );
     341        long b = imm2int( rhs );
    332342        if ( a > 0 )
    333343            return int2imm( a / b );
     
    354364        return int2imm( 0 );
    355365    else {
    356         int a = imm2int( lhs );
    357         int b = imm2int( rhs );
     366        long a = imm2int( lhs );
     367        long b = imm2int( rhs );
    358368        if ( a > 0 )
    359369            if ( b > 0 )
     
    363373        else
    364374            if ( b > 0 ) {
    365                 int r = (-a) % b;
     375                long r = (-a) % b;
    366376                return int2imm( (r==0) ? r : b-r );
    367377            }
    368378            else {
    369                 int r = (-a) % (-b);
     379                long r = (-a) % (-b);
    370380                return int2imm( (r==0) ? r : -b-r );
    371381            }
     
    387397    if ( cf_glob_switches.isOn( SW_RATIONAL ) ) {
    388398        q = imm_divrat( lhs, rhs );
    389         r = CFFactory::basic( 0 );
     399        r = CFFactory::basic( 0L );
    390400    }
    391401    else {
  • factory/int_cf.cc

    r1bc7201 rc879ee  
    8787InternalCF::den ()
    8888{
    89     return CFFactory::basic( 1 );
     89    return CFFactory::basic( 1L );
    9090}
    9191//}}}
     
    129129{
    130130    ASSERT1( 0, "bgcd() not implemented for class %s", this->classname() );
    131     return CFFactory::basic( 0 );
     131    return CFFactory::basic( 0L );
    132132}
    133133
     
    136136{
    137137    ASSERT1( 0, "bgcd() not implemented for class %s", this->classname() );
    138     return CFFactory::basic( 0 );
     138    return CFFactory::basic( 0L );
    139139}
    140140//}}}
     
    147147    ASSERT1( 0, "bextgcd() not implemented for class %s", this->classname() );
    148148    a = 0; b = 0;
    149     return CFFactory::basic( 0 );
     149    return CFFactory::basic( 0L );
    150150}
    151151
     
    155155    ASSERT1( 0, "bextgcd() not implemented for class %s", this->classname() );
    156156    a = 0; b = 0;
    157     return CFFactory::basic( 0 );
    158 }
    159 //}}}
    160 
    161 int
     157    return CFFactory::basic( 0L );
     158}
     159//}}}
     160
     161long
    162162InternalCF::intval() const
    163163{
  • factory/int_cf.h

    r1bc7201 rc879ee  
    5858    virtual bool isOne() const;
    5959    virtual bool isUnivariate() const { return false; }
    60     virtual int intval() const;
     60    virtual long intval() const;
    6161    virtual int intmod( int ) const { return 0; }
    6262    virtual int sign() const PVIRT_INT("sign");
  • factory/int_int.cc

    r1bc7201 rc879ee  
    2020
    2121InternalInteger::InternalInteger( const int i )
     22{
     23    mpz_init_set_si( thempi, i );
     24}
     25
     26InternalInteger::InternalInteger( const long i )
    2227{
    2328    mpz_init_set_si( thempi, i );
     
    221226{
    222227    ASSERT( ::is_imm( c ) == INTMARK, "incompatible base coefficients" );
    223     int cc = imm2int( c );
     228    long cc = imm2int( c );
    224229    if ( getRefCount() > 1 )
    225230    {
     
    260265{
    261266    ASSERT( ::is_imm( c ) == INTMARK, "incompatible base coefficients" );
    262     int cc = imm2int( c );
     267    long cc = imm2int( c );
    263268    if ( getRefCount() > 1 )
    264269    {
     
    315320{
    316321    ASSERT( ::is_imm( c ) == INTMARK, "incompatible base coefficients" );
    317     int cc = imm2int( c );
     322    long cc = imm2int( c );
    318323    if ( getRefCount() > 1 )
    319324    {
     
    394399         return int2imm( 1 );
    395400
    396     int cInt = imm2int( c );
     401    long cInt = imm2int( c );
    397402
    398403    // trivial cases
     
    480485    }
    481486
    482     int cInt = imm2int( c );
     487    long cInt = imm2int( c );
    483488
    484489    // trivial cases
     
    512517//}}}
    513518
    514 int InternalInteger::intval() const
    515 {
    516   return (int)mpz_get_si( thempi );
     519long InternalInteger::intval() const
     520{
     521  return mpz_get_si( thempi );
    517522}
    518523
  • factory/int_int.h

    r1bc7201 rc879ee  
    6565    }
    6666    InternalInteger( const int i );
     67    InternalInteger( const long i );
    6768    InternalInteger( const char * str, const int base=10 );
    6869    InternalInteger( const mpz_ptr );
     
    111112    InternalCF * bextgcdcoeff ( InternalCF *, CanonicalForm &, CanonicalForm & );
    112113
    113     int intval() const;
     114    long intval() const;
    114115
    115116    int intmod( int p ) const;
  • factory/int_intdiv.cc

    r1bc7201 rc879ee  
    6666            "math error: divide by zero" );
    6767
    68     int intC = imm2int( c );
     68    long intC = imm2int( c );
    6969
    7070    if ( cf_glob_switches.isOn( SW_RATIONAL ) ) {
     
    208208    }
    209209
    210     int intC = imm2int( c );
     210    long intC = imm2int( c );
    211211
    212212    if ( invert ) {
     
    293293            "math error: divide by zero" );
    294294
    295     int intC = imm2int( c );
     295    long intC = imm2int( c );
    296296
    297297    if ( cf_glob_switches.isOn( SW_RATIONAL ) ) {
  • factory/int_poly.cc

    r1bc7201 rc879ee  
    251251    }
    252252    else
    253         return CFFactory::basic( 0 );
     253        return CFFactory::basic( 0L );
    254254}
    255255
     
    273273  }
    274274  else
    275     return CFFactory::basic( 0 );
     275    return CFFactory::basic( 0L );
    276276}
    277277
     
    294294        {
    295295            delete this;
    296             return CFFactory::basic( 0 );
     296            return CFFactory::basic( 0L );
    297297        }
    298298    }
     
    311311        }
    312312        else
    313             return CFFactory::basic( 0 );
     313            return CFFactory::basic( 0L );
    314314
    315315    }
     
    334334        {
    335335            delete this;
    336             return CFFactory::basic( 0 );
     336            return CFFactory::basic( 0L );
    337337        }
    338338    }
     
    351351        }
    352352        else
    353             return CFFactory::basic( 0 );
     353            return CFFactory::basic( 0L );
    354354
    355355    }
     
    378378            {
    379379                delete this;
    380                 return CFFactory::basic(0);
     380                return CFFactory::basic(0L);
    381381            }
    382382            else
    383383            {
    384384                decRefCount();
    385                 return CFFactory::basic(0);
     385                return CFFactory::basic(0L);
    386386            }
    387387        }
     
    441441            {
    442442                delete this;
    443                 return CFFactory::basic(0);
     443                return CFFactory::basic(0L);
    444444            }
    445445            else
    446446            {
    447447                decRefCount();
    448                 return CFFactory::basic(0);
     448                return CFFactory::basic(0L);
    449449            }
    450450        }
     
    556556            firstTerm = 0;
    557557            delete this;
    558             return CFFactory::basic( 0 );
     558            return CFFactory::basic( 0L );
    559559        }
    560560    }
     
    570570        }
    571571        else
    572             return CFFactory::basic( 0 );
     572            return CFFactory::basic( 0L );
    573573    }
    574574}
     
    581581        InternalCF * dummy = aCoeff->tryInvert(M, fail);
    582582        if (fail)
    583           return CFFactory::basic( 0 );
     583          return CFFactory::basic( 0L );
    584584        if (is_imm(dummy)) dummy=this->tryMulsame(dummy, M);
    585585        else dummy = dummy->tryMulsame( this, M);
     
    626626        {
    627627          freeTermList (first);
    628           return CFFactory::basic (0);
     628          return CFFactory::basic (0L);
    629629        }
    630630        newcoeff= reduce (newcoeff, M);
     
    659659            firstTerm = 0;
    660660            delete this;
    661             return CFFactory::basic( 0 );
     661            return CFFactory::basic( 0L );
    662662        }
    663663    }
     
    673673        }
    674674        else
    675             return CFFactory::basic( 0 );
     675            return CFFactory::basic( 0L );
    676676    }
    677677}
     
    689689    {
    690690        if ( deleteObject() ) delete this;
    691         return CFFactory::basic( 0 );
     691        return CFFactory::basic( 0L );
    692692    }
    693693    InternalPoly *aPoly = (InternalPoly*)aCoeff;
     
    736736            firstTerm = 0;
    737737            delete this;
    738             return CFFactory::basic( 0 );
     738            return CFFactory::basic( 0L );
    739739        }
    740740    }
     
    750750        }
    751751        else
    752             return CFFactory::basic( 0 );
     752            return CFFactory::basic( 0L );
    753753    }
    754754}
     
    762762        InternalCF * dummy = acoeff->invert();
    763763        quot = dummy->mulsame( this );
    764         rem = CFFactory::basic( 0 );
     764        rem = CFFactory::basic( 0L );
    765765    }
    766766    else
     
    793793                quot = new InternalPoly( resultfirst, resultlast, var );
    794794        else
    795             quot = CFFactory::basic( 0 );
     795            quot = CFFactory::basic( 0L );
    796796        if ( first )
    797797            if ( first->exp == 0 )
     
    803803                rem = new InternalPoly( first, last, var );
    804804        else
    805             rem = CFFactory::basic( 0 );
     805            rem = CFFactory::basic( 0L );
    806806    }
    807807}
     
    853853                quot = new InternalPoly( resultfirst, resultlast, var );
    854854        else
    855             quot = CFFactory::basic( 0 );
     855            quot = CFFactory::basic( 0L );
    856856        if ( first )
    857857            if ( first->exp == 0 )
     
    863863                rem = new InternalPoly( first, last, var );
    864864        else
    865             rem = CFFactory::basic( 0 );
     865            rem = CFFactory::basic( 0L );
    866866    }
    867867    else
     
    882882         return false;
    883883       quot = dummy->tryMulsame( this, M);
    884        rem = CFFactory::basic( 0 );
     884       rem = CFFactory::basic( 0L );
    885885       if (fail)
    886886         return false;
     
    928928                quot = new InternalPoly( resultfirst, resultlast, var );
    929929        else
    930             quot = CFFactory::basic( 0 );
     930            quot = CFFactory::basic( 0L );
    931931        if ( first )
    932932            if ( first->exp == 0 )
     
    939939                if (first->coeff.isZero())
    940940                {
    941                   rem= CFFactory::basic (0);
     941                  rem= CFFactory::basic (0L);
    942942                  delete first;
    943943                }
     
    946946            }
    947947        else
    948             rem = CFFactory::basic( 0 );
     948            rem = CFFactory::basic( 0L );
    949949    }
    950950    else
     
    11821182        {
    11831183            delete this;
    1184             return CFFactory::basic( 0 );
     1184            return CFFactory::basic( 0L );
    11851185        }
    11861186        else
    11871187        {
    11881188            decRefCount();
    1189             return CFFactory::basic( 0 );
     1189            return CFFactory::basic( 0L );
    11901190        }
    11911191    }
     
    11961196        if ( getRefCount() <= 1 )
    11971197        {
    1198             mulTermList( firstTerm, c, 0 );
     1198            mulTermList( firstTerm, c, 0L );
    11991199            return this;
    12001200        }
     
    12441244        {
    12451245            delete this;
    1246             return CFFactory::basic( 0 );
     1246            return CFFactory::basic( 0L );
    12471247        }
    12481248        else
    12491249        {
    12501250            decRefCount();
    1251             return CFFactory::basic( 0 );
     1251            return CFFactory::basic( 0L );
    12521252        }
    12531253    }
     
    12701270            {
    12711271                delete this;
    1272                 return CFFactory::basic( 0 );
     1272                return CFFactory::basic( 0L );
    12731273            }
    12741274        }
     
    12891289            {
    12901290                delete first;
    1291                 return CFFactory::basic( 0 );
     1291                return CFFactory::basic( 0L );
    12921292            }
    12931293        }
     
    13381338        {
    13391339            delete this;
    1340             return CFFactory::basic( 0 );
     1340            return CFFactory::basic( 0L );
    13411341        }
    13421342        else
    13431343        {
    13441344            decRefCount();
    1345             return CFFactory::basic( 0 );
     1345            return CFFactory::basic( 0L );
    13461346        }
    13471347    }
     
    13651365            {
    13661366                delete this;
    1367                 return CFFactory::basic( 0 );
     1367                return CFFactory::basic( 0L );
    13681368            }
    13691369        }
     
    13841384            {
    13851385                delete first;
    1386                 return CFFactory::basic( 0 );
     1386                return CFFactory::basic( 0L );
    13871387            }
    13881388        }
     
    14161416        {
    14171417            delete this;
    1418             return CFFactory::basic( 0 );
     1418            return CFFactory::basic( 0L );
    14191419        }
    14201420        else
    14211421        {
    14221422            decRefCount();
    1423             return CFFactory::basic( 0 );
     1423            return CFFactory::basic( 0L );
    14241424        }
    14251425    }
     
    14421442            {
    14431443                delete this;
    1444                 return CFFactory::basic( 0 );
     1444                return CFFactory::basic( 0L );
    14451445            }
    14461446        }
     
    14611461            {
    14621462                delete first;
    1463                 return CFFactory::basic( 0 );
     1463                return CFFactory::basic( 0L );
    14641464            }
    14651465        }
     
    15001500        {
    15011501            delete this;
    1502             return CFFactory::basic( 0 );
     1502            return CFFactory::basic( 0L );
    15031503        }
    15041504        else
    15051505        {
    15061506            decRefCount();
    1507             return CFFactory::basic( 0 );
     1507            return CFFactory::basic( 0L );
    15081508        }
    15091509    }
     
    15181518            {
    15191519              delete this;
    1520               return CFFactory::basic (0);
     1520              return CFFactory::basic (0L);
    15211521            }
    15221522            if ( firstTerm && firstTerm->exp != 0 )
     
    15311531            {
    15321532                delete this;
    1533                 return CFFactory::basic( 0 );
     1533                return CFFactory::basic( 0L );
    15341534            }
    15351535        }
     
    15421542            {
    15431543              delete this;
    1544               return CFFactory::basic (0);
     1544              return CFFactory::basic (0L);
    15451545            }
    15461546            if (fail)
    15471547            {
    15481548              delete first;
    1549               return CFFactory::basic (0);
     1549              return CFFactory::basic (0L);
    15501550            }
    15511551            if ( first && first->exp != 0 )
     
    15601560            {
    15611561                delete first;
    1562                 return CFFactory::basic( 0 );
     1562                return CFFactory::basic( 0L );
    15631563            }
    15641564        }
     
    15771577    ASSERT( ! c.isZero(), "divide by zero!" );
    15781578    if ( deleteObject() ) delete this;
    1579     return CFFactory::basic( 0 );
     1579    return CFFactory::basic( 0L );
    15801580}
    15811581
     
    15951595        {
    15961596            delete this;
    1597             return CFFactory::basic( 0 );
     1597            return CFFactory::basic( 0L );
    15981598        }
    15991599        else
    16001600        {
    16011601            decRefCount();
    1602             return CFFactory::basic( 0 );
     1602            return CFFactory::basic( 0L );
    16031603        }
    16041604    }
     
    16191619            {
    16201620                delete this;
    1621                 return CFFactory::basic( 0 );
     1621                return CFFactory::basic( 0L );
    16221622            }
    16231623        }
     
    16381638            {
    16391639                delete first;
    1640                 return CFFactory::basic( 0 );
     1640                return CFFactory::basic( 0L );
    16411641            }
    16421642        }
     
    16511651        quot = copyObject();
    16521652        quot = quot->dividecoeff( cc, invert );
    1653         rem = CFFactory::basic( 0 );
     1653        rem = CFFactory::basic( 0L );
    16541654    }
    16551655    else  if ( invert )
     
    16591659        else
    16601660            rem = cc->copyObject();
    1661         quot = CFFactory::basic( 0 );
     1661        quot = CFFactory::basic( 0L );
    16621662    }
    16631663    else
     
    16761676                quot = new InternalPoly( quotfirst, quotlast, var );
    16771677        else
    1678             quot = CFFactory::basic( 0 );
    1679         rem = CFFactory::basic( 0 );
     1678            quot = CFFactory::basic( 0L );
     1679        rem = CFFactory::basic( 0L );
    16801680    }
    16811681}
     
    16881688        quot = copyObject();
    16891689        quot = quot->dividecoeff( cc, invert );
    1690         rem = CFFactory::basic( 0 );
     1690        rem = CFFactory::basic( 0L );
    16911691        return true;
    16921692    }
     
    16971697        else
    16981698            rem = cc->copyObject();
    1699         quot = CFFactory::basic( 0 );
     1699        quot = CFFactory::basic( 0L );
    17001700        return true;
    17011701    }
     
    17371737                quot = new InternalPoly( quotfirst, quotcursor, var );
    17381738        else
    1739             quot = CFFactory::basic( 0 );
    1740         rem = CFFactory::basic( 0 );
     1739            quot = CFFactory::basic( 0L );
     1740        rem = CFFactory::basic( 0L );
    17411741    }
    17421742    else
     
    17561756        if (fail)
    17571757          return false;
    1758         rem = CFFactory::basic( 0 );
     1758        rem = CFFactory::basic( 0L );
    17591759        return true;
    17601760    }
     
    17651765        else
    17661766            rem = cc->copyObject();
    1767         quot = CFFactory::basic( 0 );
     1767        quot = CFFactory::basic( 0L );
    17681768        return true;
    17691769    }
     
    18101810                quot = new InternalPoly( quotfirst, quotcursor, var );
    18111811        else
    1812             quot = CFFactory::basic( 0 );
    1813         rem = CFFactory::basic( 0 );
     1812            quot = CFFactory::basic( 0L );
     1813        rem = CFFactory::basic( 0L );
    18141814    }
    18151815    else
  • factory/int_pp.cc

    r1bc7201 rc879ee  
    243243    if ( c == this ) {
    244244        if ( deleteObject() ) delete this;
    245         return CFFactory::basic( 1 );
     245        return CFFactory::basic( 1L );
    246246    }
    247247    if ( getRefCount() > 1 ) {
     
    276276{
    277277    if ( deleteObject() ) delete this;
    278     return CFFactory::basic( 0 );
     278    return CFFactory::basic( 0L );
    279279}
    280280
     
    283283{
    284284    if ( deleteObject() ) delete this;
    285     return CFFactory::basic( 0 );
     285    return CFFactory::basic( 0L );
    286286}
    287287
     
    290290{
    291291    if ( c == this ) {
    292         quot = CFFactory::basic( 1 );
    293         rem = CFFactory::basic( 0 );
     292        quot = CFFactory::basic( 1L );
     293        rem = CFFactory::basic( 0L );
    294294    }
    295295    else {
     
    304304        mpz_mod( b, b, primepow );
    305305        quot = new InternalPrimePower( b );
    306         rem = CFFactory::basic( 0 );
     306        rem = CFFactory::basic( 0L );
    307307    }
    308308}
     
    394394}
    395395
    396 int
     396long
    397397InternalPrimePower::intval () const
    398398{
    399   return (int)mpz_get_si( thempi );
     399  return mpz_get_si( thempi );
    400400}
    401401
  • factory/int_pp.h

    r1bc7201 rc879ee  
    8888    bool divremcoefft( InternalCF*, InternalCF*&, InternalCF*&, bool );
    8989
    90     int intval() const;
     90    long intval() const;
    9191
    9292    int intmod( int p ) const;
  • factory/int_rat.cc

    r1bc7201 rc879ee  
    2929}
    3030
     31static long intgcd( long a, long b )
     32{
     33    if ( a < 0 ) a = -a;
     34    if ( b < 0 ) b = -b;
     35
     36    long c;
     37
     38    while ( b != 0 )
     39    {
     40        c = a % b;
     41        a = b;
     42        b = c;
     43    }
     44    return a;
     45}
     46
    3147
    3248InternalRational::InternalRational()
     
    5369    {
    5470        int g = intgcd( n, d );
     71        if ( d < 0 )
     72        {
     73          mpz_init_set_si( _num, -n / g );
     74          mpz_init_set_si( _den, -d / g );
     75        }
     76        else
     77        {
     78          mpz_init_set_si( _num, n / g );
     79          mpz_init_set_si( _den, d / g );
     80        }
     81    }
     82}
     83
     84InternalRational::InternalRational( const long i )
     85{
     86    mpz_init_set_si( _num, i );
     87    mpz_init_set_si( _den, 1 );
     88}
     89
     90InternalRational::InternalRational( const long n, const long d )
     91{
     92    ASSERT( d != 0, "divide by zero" );
     93    if ( n == 0 )
     94    {
     95        mpz_init_set_si( _num, 0 );
     96        mpz_init_set_si( _den, 1 );
     97    }
     98    else
     99    {
     100        long g = intgcd( n, d );
    55101        if ( d < 0 )
    56102        {
     
    378424    {
    379425        if ( deleteObject() ) delete this;
    380         return CFFactory::basic( 1 );
     426        return CFFactory::basic( 1L );
    381427    }
    382428    else
     
    449495{
    450496    if ( deleteObject() ) delete this;
    451     return CFFactory::basic( 0 );
     497    return CFFactory::basic( 0L );
    452498}
    453499
     
    456502    quot = copyObject();
    457503    quot = quot->dividesame( c );
    458     rem = CFFactory::basic( 0 );
     504    rem = CFFactory::basic( 0L );
    459505}
    460506
     
    528574    if ( ::is_imm( c ) )
    529575    {
    530         int cc = imm2int( c );
     576        long cc = imm2int( c );
    531577        if ( cc == 0 )
    532578            return this;
     
    565611    if ( ::is_imm( c ) )
    566612    {
    567         int cc = imm2int( c );
     613        long cc = imm2int( c );
    568614        if ( cc == 0 )
    569615        {
     
    622668    if ( ::is_imm( c ) )
    623669    {
    624         int cc = imm2int( c );
     670        long cc = imm2int( c );
    625671        if ( cc == 0 )
    626672        {
    627673            if ( deleteObject() ) delete this;
    628             return CFFactory::basic( 0 );
     674            return CFFactory::basic( 0L );
    629675        }
    630676        mpz_init_set_si( n, cc );
     
    675721    if ( ::is_imm( c ) )
    676722    {
    677         int cc = imm2int( c );
     723        long cc = imm2int( c );
    678724        ASSERT( c != 0 || invert, "divide by zero" );
    679725        if ( cc == 0 )
     
    681727            // => invert
    682728            if ( deleteObject() ) delete this;
    683             return CFFactory::basic( 0 );
     729            return CFFactory::basic( 0L );
    684730        }
    685731        if ( invert )
     
    764810    ASSERT( invert || ! ::is_imm( c ) || imm2int( c ) != 0, "divide by zero" );
    765811    if ( deleteObject() ) delete this;
    766     return CFFactory::basic( 0 );
     812    return CFFactory::basic( 0L );
    767813}
    768814
     
    771817    quot = copyObject();
    772818    quot = quot->dividecoeff( c, invert );
    773     rem = CFFactory::basic( 0 );
     819    rem = CFFactory::basic( 0L );
    774820}
    775821
     
    851897
    852898
    853 int InternalRational::intval() const
    854 {
     899long InternalRational::intval() const
     900{
     901
    855902    ASSERT( mpz_cmp_si( _den, 1 ) == 0, "illegal operation" );
    856     return (int)mpz_get_si( _num );
     903    return mpz_get_si( _num );
     904
    857905}
    858906
  • factory/int_rat.h

    r1bc7201 rc879ee  
    4040    InternalRational( const int i );
    4141    InternalRational( const int n, const int d );
     42    InternalRational( const long i );
     43    InternalRational( const long n, const long d );
    4244    InternalRational( const char * str );
    4345    InternalRational( const mpz_ptr );
     
    9092    InternalCF * bextgcdcoeff ( InternalCF *, CanonicalForm &, CanonicalForm & );
    9193
    92     int intval() const;
     94    long intval() const;
    9395
    9496    int sign() const;
  • libpolys/coeffs/longrat.cc

    r1bc7201 rc879ee  
    267267    {
    268268      mpz_t dummy;
    269       mpz_init_set( dummy,n->z );
    270       term = make_cf( dummy );
     269      long lz=mpz_get_si(n->z);
     270      if (mpz_cmp_si(n->z,lz)==0) term=lz;
     271      else
     272      {
     273        mpz_init_set( dummy,n->z );
     274        term = make_cf( dummy );
     275      }
    271276    }
    272277    else
     
    287292  if (n.isImm())
    288293  {
     294    long lz=n.intval();
     295    int iz=(int)lz;
     296    if ((long)iz==lz)
     297    {
     298      return nlInit(n.intval(),r);
     299    }
     300    else  return nlRInit(lz);
    289301    return nlInit(n.intval(),r);
    290302  }
  • libpolys/polys/clapconv.cc

    r1bc7201 rc879ee  
    245245{
    246246  if ( f.isImm() )
    247     return n_Init( f.intval(), r->cf->extRing->cf);
     247  {
     248    long longf=f.intval();
     249    int intf=(int) longf;
     250    if((long)intf==longf)
     251    {
     252      assume (r->cf->extRing != NULL);
     253      return n_Init(f.intval(),r->cf->extRing->cf);
     254    }
     255    else return nlRInit( longf );
     256  }
    248257  else
    249258  {
Note: See TracChangeset for help on using the changeset viewer.