Index: Tst/Old/m17ex.res.gz.uu
===================================================================
--- Tst/Old/m17ex.res.gz.uu	(revision 1bc7201c1a771fb5cc842ca4f475ba3ea91e6979)
+++ Tst/Old/m17ex.res.gz.uu	(revision c879eea1669e963fb4c7287a3963abb287d00a49)
@@ -1,13 +1,13 @@
-begin 640 m17ex.res.gz
-M'XL("(8/CDP``VTQ-V5X+G)E<P"-4CU/PS`0W?,K3A5#OAIJ)TU3JC`@EDJ(
-MI=U002%-BJ625K$K^?CUG)O4*0P(#_;9?N_=O=.MUH_+9P!@][2UHME!"_DD
-M='6(7K@]+IQ5#^`&<#SL$6K(8:Y9.F:99C'R,5TXQ@$=$TS.KPQY$*<ZP\3R
-MXPCL"@@SPZF!3C$E8MKQ8DQ)C.,LF&,VI$Y,ZMM;DQ9\<#41D7NO_'Q)QUR;
-M(I@V-6#B6=K49*R+4AU:\56YM;=P7MCFSJ'7-PKR>1?Q36Y%>HWN(][D8ST-
-MD#N$.=-8R$)N]=.^K+92I[:1?2H)1;.%S]->B>->E$*)2H9@2;.H(]6BE:JG
-M@"`2E(=&JJ)1D<5FT:7E._+N8A+HS/-=S:DF;VC/_/Z'S]UOGVSP:9C6G,Z,
-MU6MO[*+))KVW]4<%LOBL0#10?A1MJ:I62"5*X'<6S**KV>%7LT,"OD_]V5:U
-M:+I_W[>T8:+^LL?B_]L+<#!'*E?>>&@GD=$X/2T?8*2DBO;B?;2@X(U:KT[2
-.9=[BQOD&`C*U1A0#````
+begin 644 m17ex.res.gz
+M'XL("-SF^D\``VTQ-V5X+G)E<P"-4DM/PD`0OO=73(B'OJCLMI0BJ0?CA<1X
+M@9M!4TN+FV`AW279\=<[2\L6/1A[V.[C>\PWF=7Z<?D,`.R>EE8T.V@AGX2N
+M#M$+M\>%L^H!W`".ASU"#3G,-4O'+-,L1CZF`\<XH-\$D_,M0Q[$J<XPL?PX
+M`OL%A)GAU$"GF!(Q[7@QIB3&<1;,,1NL$V-]>VMLP0=7$Q&Y]\K/AW3,M2F"
+M:5,#)IZE38UC793JT(JORJV]A?/"-G<.W;[1)I]W.[[)K4BOT3W$FWRLIP%R
+MAS!G&@M9R*U^VI?55NK4-K*WDE`T6_@\[94X[D4IE*AD")8TBSI2+5JI>@H(
+M(D%Y:*0J&A59;!9=6KZC["XF@<X\W]6<:O*&]LSO?^3<_<[)AIR&:</IS$2]
+MSL8NFFS29UM_5""+SPI$`^5'T9)+U0JI1`G\SJ)9=#4\_&IX2,'WJ4';JA9-
+M]^[[EC:,U%_Y6/S_?`$.Z4CE*AP/[2@RFJ>GY0.,E%317KR/%K1YH]ZKDW29
+-M[AQO@%*)IX/%0,`````
 `
 end
Index: Tst/Old/m17ex.stat
===================================================================
--- Tst/Old/m17ex.stat	(revision 1bc7201c1a771fb5cc842ca4f475ba3ea91e6979)
+++ Tst/Old/m17ex.stat	(revision c879eea1669e963fb4c7287a3963abb287d00a49)
@@ -1,4 +1,4 @@
-1 >> tst_memory_0 :: 1284378480:3115- 13145 :3-1-1:ix86-Linux:mamawutz:171372 1292524760:3120- 13145 :3-1-2:ix86-Linux:mamawutz:171636
-1 >> tst_memory_1 :: 1284378480:3115- 13145 :3-1-1:ix86-Linux:mamawutz:667288 1292524760:3120- 13145 :3-1-2:ix86-Linux:mamawutz:667336
-1 >> tst_memory_2 :: 1284378480:3115- 13145 :3-1-1:ix86-Linux:mamawutz:700072 1292524760:3120- 13145 :3-1-2:ix86-Linux:mamawutz:700120
-1 >> tst_timer_1 :: 1284378480:3115- 13145 :3-1-1:ix86-Linux:mamawutz:5 1292524760:3120- 13145 :3-1-2:ix86-Linux:mamawutz:5
+1 >> tst_memory_0 :: 1341843164:3144- exported :3-1-4:ix86-Linux:mamawutz:180696
+1 >> tst_memory_1 :: 1341843164:3144- exported :3-1-4:ix86-Linux:mamawutz:2240284
+1 >> tst_memory_2 :: 1341843164:3144- exported :3-1-4:ix86-Linux:mamawutz:2273068
+1 >> tst_timer_1 :: 1341843164:3144- exported :3-1-4:ix86-Linux:mamawutz:2
Index: Tst/Old/m17ex.tst
===================================================================
--- Tst/Old/m17ex.tst	(revision 1bc7201c1a771fb5cc842ca4f475ba3ea91e6979)
+++ Tst/Old/m17ex.tst	(revision c879eea1669e963fb4c7287a3963abb287d00a49)
@@ -8,5 +8,5 @@
   poly g = (y4+x8)*(x2+y2);
   factorize(g);
-  // The same in charcteristic 2:
+  // The same in characteristic 2:
   ring r =2,(x,y),dp;
   poly g = (y4+x8)*(x2+y2);
Index: factory/FLINTconvert.cc
===================================================================
--- factory/FLINTconvert.cc	(revision 1bc7201c1a771fb5cc842ca4f475ba3ea91e6979)
+++ factory/FLINTconvert.cc	(revision c879eea1669e963fb4c7287a3963abb287d00a49)
@@ -140,5 +140,5 @@
     ulong coeff= nmod_poly_get_coeff_ui (poly, i);
     if (!coeff == 0)
-      result += CanonicalForm (coeff)*power (x,i);
+      result += CanonicalForm ((long)coeff)*power (x,i);
   }
   return result;
Index: factory/README
===================================================================
--- factory/README	(revision 1bc7201c1a771fb5cc842ca4f475ba3ea91e6979)
+++ factory/README	(revision c879eea1669e963fb4c7287a3963abb287d00a49)
@@ -338,8 +338,6 @@
 continuation):
 
-  g++ -c /usr/local/include/templates/ftmpl_inst.cc \
-    -fno-implicit-templates -O2 -fomit-frame-pointer -o ftmpl_inst.o
-  g++ -c application.cc -fno-implicit-templates -O2 -fomit-frame-pointer \
-    ftmpl_inst.o -lcf -lcfmem -lm -lgmp
+  g++ -c /usr/local/include/templates/ftmpl_inst.cc -fno-implicit-templates -O2 -fomit-frame-pointer -o ftmpl_inst.o
+  g++ -c application.cc -fno-implicit-templates -O2 -fomit-frame-pointer ftmpl_inst.o -lcf -lcfmem -lm -lgmp
 
   This should work fine provided that you installed Factory in a location
Index: factory/canonicalform.cc
===================================================================
--- factory/canonicalform.cc	(revision 1bc7201c1a771fb5cc842ca4f475ba3ea91e6979)
+++ factory/canonicalform.cc	(revision c879eea1669e963fb4c7287a3963abb287d00a49)
@@ -217,5 +217,5 @@
 
 //{{{ conversion functions
-int
+long
 CanonicalForm::intval() const
 {
@@ -1303,15 +1303,15 @@
     if ( is_imm( value ) ) {
         ASSERT( is_imm( value ) == INTMARK, "sqrt() not implemented" );
-        int n = imm2int( value );
+        long n = imm2int( value );
         ASSERT( n >= 0, "arg to sqrt() less than zero" );
         if ( n == 0 || n == 1 )
             return CanonicalForm( n );
         else {
-            int x, y = n;
+            long x, y = n;
             do {
                 x = y;
                 // the intermediate result may not fit into an
                 // integer, but the result does
-                y = (unsigned int)(x + n/x)/2;
+                y = (unsigned long)(x + n/x)/2;
             } while ( y < x );
             return CanonicalForm( x );
@@ -1340,5 +1340,5 @@
     {
         ASSERT( is_imm( value ) == INTMARK, "ilog2() not implemented" );
-        int a = imm2int( value );
+        long a = imm2int( value );
         ASSERT( a > 0, "arg to ilog2() less or equal zero" );
         int n = -1;
@@ -1584,6 +1584,6 @@
             // calculate gcd using standard integer
             // arithmetic
-            int fInt = imm2int( f.value );
-            int gInt = imm2int( g.value );
+            long fInt = imm2int( f.value );
+            long gInt = imm2int( g.value );
 
             if ( fInt < 0 ) fInt = -fInt;
@@ -1592,5 +1592,5 @@
             if ( gInt > fInt )
             {
-                int swap = gInt;
+                long swap = gInt;
                 gInt = fInt;
                 fInt = swap;
@@ -1601,5 +1601,5 @@
             {
                 // calculate (fInt, gInt) = (gInt, fInt%gInt)
-                int r = fInt % gInt;
+                long r = fInt % gInt;
                 fInt = gInt;
                 gInt = r;
@@ -1658,6 +1658,6 @@
             // calculate extended gcd using standard integer
             // arithmetic
-            int fInt = imm2int( f.value );
-            int gInt = imm2int( g.value );
+            long fInt = imm2int( f.value );
+            long gInt = imm2int( g.value );
 
             // to avoid any system dpendencies with `%', we work
@@ -1668,11 +1668,11 @@
             // swap fInt and gInt
             if ( gInt > fInt ) {
-                int swap = gInt;
+                long swap = gInt;
                 gInt = fInt;
                 fInt = swap;
             }
 
-            int u = 1; int v = 0;
-            int uNext = 0; int vNext = 1;
+            long u = 1; long v = 0;
+            long uNext = 0; long vNext = 1;
 
             // at any step, we have:
@@ -1682,8 +1682,8 @@
             // and gInt, resp., at the beginning
             while ( gInt ) {
-                int r = fInt % gInt;
-                int q = fInt / gInt;
-                int uSwap = u - q * uNext;
-                int vSwap = v - q * vNext;
+                long r = fInt % gInt;
+                long q = fInt / gInt;
+                long uSwap = u - q * uNext;
+                long vSwap = v - q * vNext;
 
                 // update variables
@@ -1695,6 +1695,6 @@
 
             // now, assign to a and b
-            int fTest = imm2int( f.value );
-            int gTest = imm2int( g.value );
+            long fTest = imm2int( f.value );
+            long gTest = imm2int( g.value );
             if ( gTest > fTest ) {
                 a = v; b = u;
@@ -1804,9 +1804,9 @@
     int what = is_imm( value );
     if ( what == FFMARK )
-        return CanonicalForm( CFFactory::basic( FiniteFieldDomain, 0 ) );
+        return CanonicalForm( CFFactory::basic( FiniteFieldDomain, 0L ) );
     else  if ( what == GFMARK )
-        return CanonicalForm( CFFactory::basic( GaloisFieldDomain, 0 ) );
+        return CanonicalForm( CFFactory::basic( GaloisFieldDomain, 0L ) );
     else  if ( what )
-        return CanonicalForm( CFFactory::basic( IntegerDomain, 0 ) );
+        return CanonicalForm( CFFactory::basic( IntegerDomain, 0L ) );
     else
         return CanonicalForm( value->genZero() );
@@ -1818,9 +1818,9 @@
     int what = is_imm( value );
     if ( what == FFMARK )
-        return CanonicalForm( CFFactory::basic( FiniteFieldDomain, 1 ) );
+        return CanonicalForm( CFFactory::basic( FiniteFieldDomain, 1L ) );
     else  if ( what == GFMARK )
-        return CanonicalForm( CFFactory::basic( GaloisFieldDomain, 1 ) );
+        return CanonicalForm( CFFactory::basic( GaloisFieldDomain, 1L ) );
     else  if ( what )
-        return CanonicalForm( CFFactory::basic( IntegerDomain, 1 ) );
+        return CanonicalForm( CFFactory::basic( IntegerDomain, 1L ) );
     else
         return CanonicalForm( value->genOne() );
Index: factory/canonicalform.h
===================================================================
--- factory/canonicalform.h	(revision 1bc7201c1a771fb5cc842ca4f475ba3ea91e6979)
+++ factory/canonicalform.h	(revision c879eea1669e963fb4c7287a3963abb287d00a49)
@@ -69,4 +69,5 @@
     CF_INLINE CanonicalForm( InternalCF* );
     CF_INLINE CanonicalForm( const int );
+    CF_INLINE CanonicalForm( const long );
     CF_INLINE CanonicalForm( const Variable & );
     CF_INLINE CanonicalForm( const Variable &, int );
@@ -100,5 +101,5 @@
 
     // conversion functions
-    int intval() const;
+    long intval() const;
     CanonicalForm mapinto () const;
 
@@ -123,5 +124,5 @@
     // assignment operators
     CF_NO_INLINE CanonicalForm& operator = ( const CanonicalForm& );
-    CF_NO_INLINE CanonicalForm& operator = ( const int );
+    CF_NO_INLINE CanonicalForm& operator = ( const long );
 
     CanonicalForm& operator += ( const CanonicalForm& );
Index: factory/cf_factor.cc
===================================================================
--- factory/cf_factor.cc	(revision 1bc7201c1a771fb5cc842ca4f475ba3ea91e6979)
+++ factory/cf_factor.cc	(revision c879eea1669e963fb4c7287a3963abb287d00a49)
@@ -89,5 +89,5 @@
 }
 
-#if 0
+#if 1
 //#ifndef NOSTREAMIO
 void out_cf(const char *s1,const CanonicalForm &f,const char *s2)
Index: factory/cf_factory.cc
===================================================================
--- factory/cf_factory.cc	(revision 1bc7201c1a771fb5cc842ca4f475ba3ea91e6979)
+++ factory/cf_factory.cc	(revision c879eea1669e963fb4c7287a3963abb287d00a49)
@@ -25,5 +25,5 @@
 
 InternalCF *
-CFFactory::basic ( int value )
+CFFactory::basic ( long value )
 {
     if ( currenttype == IntegerDomain )
@@ -50,5 +50,5 @@
 
 InternalCF *
-CFFactory::basic ( int type, int value )
+CFFactory::basic ( int type, long value )
 {
     if ( type == IntegerDomain )
@@ -204,5 +204,5 @@
 
 InternalCF *
-CFFactory::basic ( int type, int value, bool nonimm )
+CFFactory::basic ( int type, long value, bool nonimm )
 {
     if ( nonimm )
@@ -231,5 +231,5 @@
 
 InternalCF *
-CFFactory::rational ( int num, int den )
+CFFactory::rational ( long num, long den )
 {
     InternalRational * res = new InternalRational( num, den );
Index: factory/cf_factory.h
===================================================================
--- factory/cf_factory.h	(revision 1bc7201c1a771fb5cc842ca4f475ba3ea91e6979)
+++ factory/cf_factory.h	(revision c879eea1669e963fb4c7287a3963abb287d00a49)
@@ -21,12 +21,12 @@
     static int gettype () { return currenttype; }
     static void settype ( int type );
-    static InternalCF * basic ( int value );
-    static InternalCF * basic ( int type, int value );
+    static InternalCF * basic ( long value );
+    static InternalCF * basic ( int type, long value );
     static InternalCF * basic ( const char * str );
     static InternalCF * basic ( const char * str, int base );
     static InternalCF * basic ( int type, const char * const str );
-    static InternalCF * basic ( int type, int value, bool nonimm );
+    static InternalCF * basic ( int type, long value, bool nonimm );
     static InternalCF * basic ( const mpz_ptr num );
-    static InternalCF * rational ( int num, int den );
+    static InternalCF * rational ( long num, long den );
     static InternalCF * rational ( const mpz_ptr num, const mpz_ptr den, bool normalize );
     static InternalCF * poly ( const Variable & v, int exp, const CanonicalForm & c );
Index: factory/cf_inline.cc
===================================================================
--- factory/cf_inline.cc	(revision 1bc7201c1a771fb5cc842ca4f475ba3ea91e6979)
+++ factory/cf_inline.cc	(revision c879eea1669e963fb4c7287a3963abb287d00a49)
@@ -121,5 +121,5 @@
 CF_INLINE
 CanonicalForm::CanonicalForm ()
-    : value( CFFactory::basic( (int)0 ) )
+    : value( CFFactory::basic( (long)0 ) )
 {
 }
@@ -140,4 +140,10 @@
 CF_INLINE
 CanonicalForm::CanonicalForm ( const int i )
+    : value( CFFactory::basic( (long)i ) )
+{
+}
+
+CF_INLINE
+CanonicalForm::CanonicalForm ( const long i )
     : value( CFFactory::basic( i ) )
 {
@@ -300,5 +306,5 @@
 //}}}
 CF_INLINE CanonicalForm &
-CanonicalForm::operator = ( const int cf )
+CanonicalForm::operator = ( const long cf )
 {
     if ( (! is_imm( value )) && value->deleteObject() )
Index: factory/ffops.h
===================================================================
--- factory/ffops.h	(revision 1bc7201c1a771fb5cc842ca4f475ba3ea91e6979)
+++ factory/ffops.h	(revision c879eea1669e963fb4c7287a3963abb287d00a49)
@@ -37,5 +37,25 @@
 }
 
+inline long ff_norm ( const long a )
+{
+    long n = a % ff_prime;
+#if defined(i386) || defined(NTL_AVOID_BRANCHING)
+    n += (n >> 31) & ff_prime;
+    return n;
+#else
+    if (n < 0) n += ff_prime;
+    return n;
+#endif
+}
+
 inline int ff_symmetric( const int a )
+{
+    if ( cf_glob_switches.isOn( SW_SYMMETRIC_FF ) )
+        return ( a > ff_halfprime ) ? a - ff_prime : a;
+    else
+        return a;
+}
+
+inline long ff_symmetric( const long a )
 {
     if ( cf_glob_switches.isOn( SW_SYMMETRIC_FF ) )
Index: factory/gfops.cc
===================================================================
--- factory/gfops.cc	(revision 1bc7201c1a771fb5cc842ca4f475ba3ea91e6979)
+++ factory/gfops.cc	(revision c879eea1669e963fb4c7287a3963abb287d00a49)
@@ -222,4 +222,26 @@
 }
 
+long gf_gf2ff ( long a )
+{
+    if ( gf_iszero( a ) )
+        return 0;
+    else
+    {
+        // starting from z^0=1, step through the table
+        // counting the steps until we hit z^a or z^0
+        // again.  since we are working in char(p), the
+        // latter is guaranteed to be fulfilled.
+        long i = 0, ff = 1;
+        do
+        {
+            if ( i == a )
+                return ff;
+            ff++;
+            i = gf_table[i];
+        } while ( i != 0 );
+        return -1;
+    }
+}
+
 int gf_gf2ff ( int a )
 {
@@ -244,5 +266,5 @@
 }
 
-bool gf_isff ( int a )
+bool gf_isff ( long a )
 {
     if ( gf_iszero( a ) )
@@ -254,2 +276,13 @@
     }
 }
+
+bool gf_isff ( int a )
+{
+    if ( gf_iszero( a ) )
+        return true;
+    else
+    {
+        // z^a in GF(p) iff (z^a)^p-1=1
+        return gf_isone( gf_power( a, gf_p - 1 ) );
+    }
+}
Index: factory/gfops.h
===================================================================
--- factory/gfops.h	(revision 1bc7201c1a771fb5cc842ca4f475ba3ea91e6979)
+++ factory/gfops.h	(revision c879eea1669e963fb4c7287a3963abb287d00a49)
@@ -38,5 +38,15 @@
 }
 
+inline bool gf_iszero ( long a )
+{
+    return gf_q == a;
+}
+
 inline bool gf_isone ( int a )
+{
+    return 0 == a;
+}
+
+inline bool gf_isone ( long a )
 {
     return 0 == a;
@@ -54,4 +64,20 @@
 	return gf_q;
     int c = 0;
+    while ( i > 1 ) {
+	c = gf_table[c];
+	i--;
+    }
+    return c;
+}
+
+inline long gf_int2gf ( long i )
+{
+    while ( i < 0 )
+	i += gf_p;
+    while ( i >= gf_p )
+	i -= gf_p;
+    if ( i == 0 )
+	return gf_q;
+    long c = 0;
     while ( i > 1 ) {
 	c = gf_table[c];
@@ -138,4 +164,15 @@
 }
 
+inline long gf_mul ( long a, int b )
+{
+    if ( a == gf_q || b == gf_q )
+	return gf_q;
+    else {
+	long i = a + b;
+	if ( i >= gf_q1 ) i -= gf_q1;
+	return i;
+    }
+}
+
 inline int gf_div ( int a, int b )
 {
@@ -184,4 +221,14 @@
 	return gf_mul( a, gf_power( a, n-1 ) );
 }
+
+inline long gf_power ( long a, int n )
+{
+    if ( n == 0 )
+	return 0;
+    else if ( n == 1 )
+	return a;
+    else
+	return gf_mul( a, gf_power( a, n-1 ) );
+}
 //}}}
 
@@ -191,6 +238,8 @@
 /*BEGINPUBLIC*/
 
+long gf_gf2ff ( long a );
 int gf_gf2ff ( int a );
 
+bool gf_isff ( long a );
 bool gf_isff ( int a );
 
Index: factory/imm.h
===================================================================
--- factory/imm.h	(revision 1bc7201c1a771fb5cc842ca4f475ba3ea91e6979)
+++ factory/imm.h	(revision c879eea1669e963fb4c7287a3963abb287d00a49)
@@ -26,7 +26,7 @@
 #include "int_cf.h"
 
-const int INTMARK = 1;
-const int FFMARK = 2;
-const int GFMARK = 3;
+const long INTMARK = 1;
+const long FFMARK = 2;
+const long GFMARK = 3;
 
 /* define type of your compilers 64 bit integer type */
@@ -35,6 +35,12 @@
 #endif
 
-const int MINIMMEDIATE = -268435454; // -2^28-2
-const int MAXIMMEDIATE = 268435454;  // 2^28-2
+#if SIZEOF_LONG == 4
+const long MINIMMEDIATE = -268435454; // -2^28-2
+const long MAXIMMEDIATE = 268435454;  // 2^28-2
+#else
+const long MINIMMEDIATE = -(1L<<60)+2L; // -2^60-2
+const long MAXIMMEDIATE = (1L<<60)-2L;  // 2^60-2
+#endif
+
 #if defined(WINNT) && ! defined(__GNUC__)
 const INT64 MINIMMEDIATELL = -268435454i64;
@@ -49,10 +55,10 @@
 #if 1
 
-inline int imm2int ( const InternalCF * const imm )
-{
-    return ((int)((long)imm)) >> 2;
-}
-
-inline InternalCF * int2imm ( int i )
+inline long imm2int ( const InternalCF * const imm )
+{
+    return ((long)imm) >> 2;
+}
+
+inline InternalCF * int2imm ( long i )
 {
     return (InternalCF*)(long)((i << 2) | INTMARK );
@@ -70,5 +76,5 @@
 }
 
-inline InternalCF * int2imm ( int i )
+inline InternalCF * int2imm ( long i )
 {
     if ( i < 0 )
@@ -80,10 +86,10 @@
 #endif
 
-inline InternalCF * int2imm_p ( int i )
+inline InternalCF * int2imm_p ( long i )
 {
     return (InternalCF*)(long)((i << 2) | FFMARK );
 }
 
-inline InternalCF * int2imm_gf ( int i )
+inline InternalCF * int2imm_gf ( long i )
 {
     return (InternalCF*)(long)((i << 2) | GFMARK );
@@ -143,5 +149,5 @@
 
 //{{{ conversion functions
-inline int imm_intval ( const InternalCF* const op )
+inline long imm_intval ( const InternalCF* const op )
 {
     if ( is_imm( op ) == FFMARK )
@@ -253,5 +259,5 @@
 inline InternalCF * imm_add ( const InternalCF * const lhs, const InternalCF * const rhs )
 {
-    int result = imm2int( lhs ) + imm2int( rhs );
+    long result = imm2int( lhs ) + imm2int( rhs );
     if ( ( result > MAXIMMEDIATE ) || ( result < MINIMMEDIATE ) )
         return CFFactory::basic( result );
@@ -272,5 +278,5 @@
 inline InternalCF * imm_sub ( const InternalCF * const lhs, const InternalCF * const rhs )
 {
-    int result = imm2int( lhs ) - imm2int( rhs );
+    long result = imm2int( lhs ) - imm2int( rhs );
     if ( ( result > MAXIMMEDIATE ) || ( result < MINIMMEDIATE ) )
         return CFFactory::basic( result );
@@ -292,11 +298,15 @@
 imm_mul ( InternalCF * lhs, InternalCF * rhs )
 {
-    INT64 result = (INT64)imm2int( lhs ) * imm2int( rhs );
-    if ( ( result > MAXIMMEDIATELL ) || ( result < MINIMMEDIATELL ) ) {
-        InternalCF * res = CFFactory::basic( IntegerDomain, imm2int( lhs ), true );
+    long a = imm2int( lhs );
+    long b = imm2int( rhs );
+    INT64 result = (INT64)a * (INT64)b;
+    if ( ( a!=0L ) && ((result/a!=b)
+      ||(result>MAXIMMEDIATE)||(result<MINIMMEDIATE) ) )
+    {
+        InternalCF * res = CFFactory::basic( IntegerDomain, a, true );
         return res->mulcoeff( rhs );
     }
     else
-        return int2imm( (int)result );
+        return int2imm( result );
 }
 
@@ -313,6 +323,6 @@
 inline InternalCF * imm_div ( const InternalCF * const lhs, const InternalCF * const rhs )
 {
-    int a = imm2int( lhs );
-    int b = imm2int( rhs );
+    long a = imm2int( lhs );
+    long b = imm2int( rhs );
     if ( a > 0 )
         return int2imm( a / b );
@@ -328,6 +338,6 @@
         return CFFactory::rational( imm2int( lhs ), imm2int( rhs ) );
     else {
-        int a = imm2int( lhs );
-        int b = imm2int( rhs );
+        long a = imm2int( lhs );
+        long b = imm2int( rhs );
         if ( a > 0 )
             return int2imm( a / b );
@@ -354,6 +364,6 @@
         return int2imm( 0 );
     else {
-        int a = imm2int( lhs );
-        int b = imm2int( rhs );
+        long a = imm2int( lhs );
+        long b = imm2int( rhs );
         if ( a > 0 )
             if ( b > 0 )
@@ -363,9 +373,9 @@
         else
             if ( b > 0 ) {
-                int r = (-a) % b;
+                long r = (-a) % b;
                 return int2imm( (r==0) ? r : b-r );
             }
             else {
-                int r = (-a) % (-b);
+                long r = (-a) % (-b);
                 return int2imm( (r==0) ? r : -b-r );
             }
@@ -387,5 +397,5 @@
     if ( cf_glob_switches.isOn( SW_RATIONAL ) ) {
         q = imm_divrat( lhs, rhs );
-        r = CFFactory::basic( 0 );
+        r = CFFactory::basic( 0L );
     }
     else {
Index: factory/int_cf.cc
===================================================================
--- factory/int_cf.cc	(revision 1bc7201c1a771fb5cc842ca4f475ba3ea91e6979)
+++ factory/int_cf.cc	(revision c879eea1669e963fb4c7287a3963abb287d00a49)
@@ -87,5 +87,5 @@
 InternalCF::den ()
 {
-    return CFFactory::basic( 1 );
+    return CFFactory::basic( 1L );
 }
 //}}}
@@ -129,5 +129,5 @@
 {
     ASSERT1( 0, "bgcd() not implemented for class %s", this->classname() );
-    return CFFactory::basic( 0 );
+    return CFFactory::basic( 0L );
 }
 
@@ -136,5 +136,5 @@
 {
     ASSERT1( 0, "bgcd() not implemented for class %s", this->classname() );
-    return CFFactory::basic( 0 );
+    return CFFactory::basic( 0L );
 }
 //}}}
@@ -147,5 +147,5 @@
     ASSERT1( 0, "bextgcd() not implemented for class %s", this->classname() );
     a = 0; b = 0;
-    return CFFactory::basic( 0 );
+    return CFFactory::basic( 0L );
 }
 
@@ -155,9 +155,9 @@
     ASSERT1( 0, "bextgcd() not implemented for class %s", this->classname() );
     a = 0; b = 0;
-    return CFFactory::basic( 0 );
-}
-//}}}
-
-int
+    return CFFactory::basic( 0L );
+}
+//}}}
+
+long
 InternalCF::intval() const
 {
Index: factory/int_cf.h
===================================================================
--- factory/int_cf.h	(revision 1bc7201c1a771fb5cc842ca4f475ba3ea91e6979)
+++ factory/int_cf.h	(revision c879eea1669e963fb4c7287a3963abb287d00a49)
@@ -58,5 +58,5 @@
     virtual bool isOne() const;
     virtual bool isUnivariate() const { return false; }
-    virtual int intval() const;
+    virtual long intval() const;
     virtual int intmod( int ) const { return 0; }
     virtual int sign() const PVIRT_INT("sign");
Index: factory/int_int.cc
===================================================================
--- factory/int_int.cc	(revision 1bc7201c1a771fb5cc842ca4f475ba3ea91e6979)
+++ factory/int_int.cc	(revision c879eea1669e963fb4c7287a3963abb287d00a49)
@@ -20,4 +20,9 @@
 
 InternalInteger::InternalInteger( const int i )
+{
+    mpz_init_set_si( thempi, i );
+}
+
+InternalInteger::InternalInteger( const long i )
 {
     mpz_init_set_si( thempi, i );
@@ -221,5 +226,5 @@
 {
     ASSERT( ::is_imm( c ) == INTMARK, "incompatible base coefficients" );
-    int cc = imm2int( c );
+    long cc = imm2int( c );
     if ( getRefCount() > 1 )
     {
@@ -260,5 +265,5 @@
 {
     ASSERT( ::is_imm( c ) == INTMARK, "incompatible base coefficients" );
-    int cc = imm2int( c );
+    long cc = imm2int( c );
     if ( getRefCount() > 1 )
     {
@@ -315,5 +320,5 @@
 {
     ASSERT( ::is_imm( c ) == INTMARK, "incompatible base coefficients" );
-    int cc = imm2int( c );
+    long cc = imm2int( c );
     if ( getRefCount() > 1 )
     {
@@ -394,5 +399,5 @@
          return int2imm( 1 );
 
-    int cInt = imm2int( c );
+    long cInt = imm2int( c );
 
     // trivial cases
@@ -480,5 +485,5 @@
     }
 
-    int cInt = imm2int( c );
+    long cInt = imm2int( c );
 
     // trivial cases
@@ -512,7 +517,7 @@
 //}}}
 
-int InternalInteger::intval() const
-{
-  return (int)mpz_get_si( thempi );
+long InternalInteger::intval() const
+{
+  return mpz_get_si( thempi );
 }
 
Index: factory/int_int.h
===================================================================
--- factory/int_int.h	(revision 1bc7201c1a771fb5cc842ca4f475ba3ea91e6979)
+++ factory/int_int.h	(revision c879eea1669e963fb4c7287a3963abb287d00a49)
@@ -65,4 +65,5 @@
     }
     InternalInteger( const int i );
+    InternalInteger( const long i );
     InternalInteger( const char * str, const int base=10 );
     InternalInteger( const mpz_ptr );
@@ -111,5 +112,5 @@
     InternalCF * bextgcdcoeff ( InternalCF *, CanonicalForm &, CanonicalForm & );
 
-    int intval() const;
+    long intval() const;
 
     int intmod( int p ) const;
Index: factory/int_intdiv.cc
===================================================================
--- factory/int_intdiv.cc	(revision 1bc7201c1a771fb5cc842ca4f475ba3ea91e6979)
+++ factory/int_intdiv.cc	(revision c879eea1669e963fb4c7287a3963abb287d00a49)
@@ -66,5 +66,5 @@
             "math error: divide by zero" );
 
-    int intC = imm2int( c );
+    long intC = imm2int( c );
 
     if ( cf_glob_switches.isOn( SW_RATIONAL ) ) {
@@ -208,5 +208,5 @@
     }
 
-    int intC = imm2int( c );
+    long intC = imm2int( c );
 
     if ( invert ) {
@@ -293,5 +293,5 @@
             "math error: divide by zero" );
 
-    int intC = imm2int( c );
+    long intC = imm2int( c );
 
     if ( cf_glob_switches.isOn( SW_RATIONAL ) ) {
Index: factory/int_poly.cc
===================================================================
--- factory/int_poly.cc	(revision 1bc7201c1a771fb5cc842ca4f475ba3ea91e6979)
+++ factory/int_poly.cc	(revision c879eea1669e963fb4c7287a3963abb287d00a49)
@@ -251,5 +251,5 @@
     }
     else
-        return CFFactory::basic( 0 );
+        return CFFactory::basic( 0L );
 }
 
@@ -273,5 +273,5 @@
   }
   else
-    return CFFactory::basic( 0 );
+    return CFFactory::basic( 0L );
 }
 
@@ -294,5 +294,5 @@
         {
             delete this;
-            return CFFactory::basic( 0 );
+            return CFFactory::basic( 0L );
         }
     }
@@ -311,5 +311,5 @@
         }
         else
-            return CFFactory::basic( 0 );
+            return CFFactory::basic( 0L );
 
     }
@@ -334,5 +334,5 @@
         {
             delete this;
-            return CFFactory::basic( 0 );
+            return CFFactory::basic( 0L );
         }
     }
@@ -351,5 +351,5 @@
         }
         else
-            return CFFactory::basic( 0 );
+            return CFFactory::basic( 0L );
 
     }
@@ -378,10 +378,10 @@
             {
                 delete this;
-                return CFFactory::basic(0);
+                return CFFactory::basic(0L);
             }
             else
             {
                 decRefCount();
-                return CFFactory::basic(0);
+                return CFFactory::basic(0L);
             }
         }
@@ -441,10 +441,10 @@
             {
                 delete this;
-                return CFFactory::basic(0);
+                return CFFactory::basic(0L);
             }
             else
             {
                 decRefCount();
-                return CFFactory::basic(0);
+                return CFFactory::basic(0L);
             }
         }
@@ -556,5 +556,5 @@
             firstTerm = 0;
             delete this;
-            return CFFactory::basic( 0 );
+            return CFFactory::basic( 0L );
         }
     }
@@ -570,5 +570,5 @@
         }
         else
-            return CFFactory::basic( 0 );
+            return CFFactory::basic( 0L );
     }
 }
@@ -581,5 +581,5 @@
         InternalCF * dummy = aCoeff->tryInvert(M, fail);
         if (fail)
-          return CFFactory::basic( 0 );
+          return CFFactory::basic( 0L );
         if (is_imm(dummy)) dummy=this->tryMulsame(dummy, M);
         else dummy = dummy->tryMulsame( this, M);
@@ -626,5 +626,5 @@
         {
           freeTermList (first);
-          return CFFactory::basic (0);
+          return CFFactory::basic (0L);
         }
         newcoeff= reduce (newcoeff, M);
@@ -659,5 +659,5 @@
             firstTerm = 0;
             delete this;
-            return CFFactory::basic( 0 );
+            return CFFactory::basic( 0L );
         }
     }
@@ -673,5 +673,5 @@
         }
         else
-            return CFFactory::basic( 0 );
+            return CFFactory::basic( 0L );
     }
 }
@@ -689,5 +689,5 @@
     {
         if ( deleteObject() ) delete this;
-        return CFFactory::basic( 0 );
+        return CFFactory::basic( 0L );
     }
     InternalPoly *aPoly = (InternalPoly*)aCoeff;
@@ -736,5 +736,5 @@
             firstTerm = 0;
             delete this;
-            return CFFactory::basic( 0 );
+            return CFFactory::basic( 0L );
         }
     }
@@ -750,5 +750,5 @@
         }
         else
-            return CFFactory::basic( 0 );
+            return CFFactory::basic( 0L );
     }
 }
@@ -762,5 +762,5 @@
         InternalCF * dummy = acoeff->invert();
         quot = dummy->mulsame( this );
-        rem = CFFactory::basic( 0 );
+        rem = CFFactory::basic( 0L );
     }
     else
@@ -793,5 +793,5 @@
                 quot = new InternalPoly( resultfirst, resultlast, var );
         else
-            quot = CFFactory::basic( 0 );
+            quot = CFFactory::basic( 0L );
         if ( first )
             if ( first->exp == 0 )
@@ -803,5 +803,5 @@
                 rem = new InternalPoly( first, last, var );
         else
-            rem = CFFactory::basic( 0 );
+            rem = CFFactory::basic( 0L );
     }
 }
@@ -853,5 +853,5 @@
                 quot = new InternalPoly( resultfirst, resultlast, var );
         else
-            quot = CFFactory::basic( 0 );
+            quot = CFFactory::basic( 0L );
         if ( first )
             if ( first->exp == 0 )
@@ -863,5 +863,5 @@
                 rem = new InternalPoly( first, last, var );
         else
-            rem = CFFactory::basic( 0 );
+            rem = CFFactory::basic( 0L );
     }
     else
@@ -882,5 +882,5 @@
          return false;
        quot = dummy->tryMulsame( this, M);
-       rem = CFFactory::basic( 0 );
+       rem = CFFactory::basic( 0L );
        if (fail)
          return false;
@@ -928,5 +928,5 @@
                 quot = new InternalPoly( resultfirst, resultlast, var );
         else
-            quot = CFFactory::basic( 0 );
+            quot = CFFactory::basic( 0L );
         if ( first )
             if ( first->exp == 0 )
@@ -939,5 +939,5 @@
                 if (first->coeff.isZero())
                 {
-                  rem= CFFactory::basic (0);
+                  rem= CFFactory::basic (0L);
                   delete first;
                 }
@@ -946,5 +946,5 @@
             }
         else
-            rem = CFFactory::basic( 0 );
+            rem = CFFactory::basic( 0L );
     }
     else
@@ -1182,10 +1182,10 @@
         {
             delete this;
-            return CFFactory::basic( 0 );
+            return CFFactory::basic( 0L );
         }
         else
         {
             decRefCount();
-            return CFFactory::basic( 0 );
+            return CFFactory::basic( 0L );
         }
     }
@@ -1196,5 +1196,5 @@
         if ( getRefCount() <= 1 )
         {
-            mulTermList( firstTerm, c, 0 );
+            mulTermList( firstTerm, c, 0L );
             return this;
         }
@@ -1244,10 +1244,10 @@
         {
             delete this;
-            return CFFactory::basic( 0 );
+            return CFFactory::basic( 0L );
         }
         else
         {
             decRefCount();
-            return CFFactory::basic( 0 );
+            return CFFactory::basic( 0L );
         }
     }
@@ -1270,5 +1270,5 @@
             {
                 delete this;
-                return CFFactory::basic( 0 );
+                return CFFactory::basic( 0L );
             }
         }
@@ -1289,5 +1289,5 @@
             {
                 delete first;
-                return CFFactory::basic( 0 );
+                return CFFactory::basic( 0L );
             }
         }
@@ -1338,10 +1338,10 @@
         {
             delete this;
-            return CFFactory::basic( 0 );
+            return CFFactory::basic( 0L );
         }
         else
         {
             decRefCount();
-            return CFFactory::basic( 0 );
+            return CFFactory::basic( 0L );
         }
     }
@@ -1365,5 +1365,5 @@
             {
                 delete this;
-                return CFFactory::basic( 0 );
+                return CFFactory::basic( 0L );
             }
         }
@@ -1384,5 +1384,5 @@
             {
                 delete first;
-                return CFFactory::basic( 0 );
+                return CFFactory::basic( 0L );
             }
         }
@@ -1416,10 +1416,10 @@
         {
             delete this;
-            return CFFactory::basic( 0 );
+            return CFFactory::basic( 0L );
         }
         else
         {
             decRefCount();
-            return CFFactory::basic( 0 );
+            return CFFactory::basic( 0L );
         }
     }
@@ -1442,5 +1442,5 @@
             {
                 delete this;
-                return CFFactory::basic( 0 );
+                return CFFactory::basic( 0L );
             }
         }
@@ -1461,5 +1461,5 @@
             {
                 delete first;
-                return CFFactory::basic( 0 );
+                return CFFactory::basic( 0L );
             }
         }
@@ -1500,10 +1500,10 @@
         {
             delete this;
-            return CFFactory::basic( 0 );
+            return CFFactory::basic( 0L );
         }
         else
         {
             decRefCount();
-            return CFFactory::basic( 0 );
+            return CFFactory::basic( 0L );
         }
     }
@@ -1518,5 +1518,5 @@
             {
               delete this;
-              return CFFactory::basic (0);
+              return CFFactory::basic (0L);
             }
             if ( firstTerm && firstTerm->exp != 0 )
@@ -1531,5 +1531,5 @@
             {
                 delete this;
-                return CFFactory::basic( 0 );
+                return CFFactory::basic( 0L );
             }
         }
@@ -1542,10 +1542,10 @@
             {
               delete this;
-              return CFFactory::basic (0);
+              return CFFactory::basic (0L);
             }
             if (fail)
             {
               delete first;
-              return CFFactory::basic (0);
+              return CFFactory::basic (0L);
             }
             if ( first && first->exp != 0 )
@@ -1560,5 +1560,5 @@
             {
                 delete first;
-                return CFFactory::basic( 0 );
+                return CFFactory::basic( 0L );
             }
         }
@@ -1577,5 +1577,5 @@
     ASSERT( ! c.isZero(), "divide by zero!" );
     if ( deleteObject() ) delete this;
-    return CFFactory::basic( 0 );
+    return CFFactory::basic( 0L );
 }
 
@@ -1595,10 +1595,10 @@
         {
             delete this;
-            return CFFactory::basic( 0 );
+            return CFFactory::basic( 0L );
         }
         else
         {
             decRefCount();
-            return CFFactory::basic( 0 );
+            return CFFactory::basic( 0L );
         }
     }
@@ -1619,5 +1619,5 @@
             {
                 delete this;
-                return CFFactory::basic( 0 );
+                return CFFactory::basic( 0L );
             }
         }
@@ -1638,5 +1638,5 @@
             {
                 delete first;
-                return CFFactory::basic( 0 );
+                return CFFactory::basic( 0L );
             }
         }
@@ -1651,5 +1651,5 @@
         quot = copyObject();
         quot = quot->dividecoeff( cc, invert );
-        rem = CFFactory::basic( 0 );
+        rem = CFFactory::basic( 0L );
     }
     else  if ( invert )
@@ -1659,5 +1659,5 @@
         else
             rem = cc->copyObject();
-        quot = CFFactory::basic( 0 );
+        quot = CFFactory::basic( 0L );
     }
     else
@@ -1676,6 +1676,6 @@
                 quot = new InternalPoly( quotfirst, quotlast, var );
         else
-            quot = CFFactory::basic( 0 );
-        rem = CFFactory::basic( 0 );
+            quot = CFFactory::basic( 0L );
+        rem = CFFactory::basic( 0L );
     }
 }
@@ -1688,5 +1688,5 @@
         quot = copyObject();
         quot = quot->dividecoeff( cc, invert );
-        rem = CFFactory::basic( 0 );
+        rem = CFFactory::basic( 0L );
         return true;
     }
@@ -1697,5 +1697,5 @@
         else
             rem = cc->copyObject();
-        quot = CFFactory::basic( 0 );
+        quot = CFFactory::basic( 0L );
         return true;
     }
@@ -1737,6 +1737,6 @@
                 quot = new InternalPoly( quotfirst, quotcursor, var );
         else
-            quot = CFFactory::basic( 0 );
-        rem = CFFactory::basic( 0 );
+            quot = CFFactory::basic( 0L );
+        rem = CFFactory::basic( 0L );
     }
     else
@@ -1756,5 +1756,5 @@
         if (fail)
           return false;
-        rem = CFFactory::basic( 0 );
+        rem = CFFactory::basic( 0L );
         return true;
     }
@@ -1765,5 +1765,5 @@
         else
             rem = cc->copyObject();
-        quot = CFFactory::basic( 0 );
+        quot = CFFactory::basic( 0L );
         return true;
     }
@@ -1810,6 +1810,6 @@
                 quot = new InternalPoly( quotfirst, quotcursor, var );
         else
-            quot = CFFactory::basic( 0 );
-        rem = CFFactory::basic( 0 );
+            quot = CFFactory::basic( 0L );
+        rem = CFFactory::basic( 0L );
     }
     else
Index: factory/int_pp.cc
===================================================================
--- factory/int_pp.cc	(revision 1bc7201c1a771fb5cc842ca4f475ba3ea91e6979)
+++ factory/int_pp.cc	(revision c879eea1669e963fb4c7287a3963abb287d00a49)
@@ -243,5 +243,5 @@
     if ( c == this ) {
         if ( deleteObject() ) delete this;
-        return CFFactory::basic( 1 );
+        return CFFactory::basic( 1L );
     }
     if ( getRefCount() > 1 ) {
@@ -276,5 +276,5 @@
 {
     if ( deleteObject() ) delete this;
-    return CFFactory::basic( 0 );
+    return CFFactory::basic( 0L );
 }
 
@@ -283,5 +283,5 @@
 {
     if ( deleteObject() ) delete this;
-    return CFFactory::basic( 0 );
+    return CFFactory::basic( 0L );
 }
 
@@ -290,6 +290,6 @@
 {
     if ( c == this ) {
-        quot = CFFactory::basic( 1 );
-        rem = CFFactory::basic( 0 );
+        quot = CFFactory::basic( 1L );
+        rem = CFFactory::basic( 0L );
     }
     else {
@@ -304,5 +304,5 @@
         mpz_mod( b, b, primepow );
         quot = new InternalPrimePower( b );
-        rem = CFFactory::basic( 0 );
+        rem = CFFactory::basic( 0L );
     }
 }
@@ -394,8 +394,8 @@
 }
 
-int
+long
 InternalPrimePower::intval () const
 {
-  return (int)mpz_get_si( thempi );
+  return mpz_get_si( thempi );
 }
 
Index: factory/int_pp.h
===================================================================
--- factory/int_pp.h	(revision 1bc7201c1a771fb5cc842ca4f475ba3ea91e6979)
+++ factory/int_pp.h	(revision c879eea1669e963fb4c7287a3963abb287d00a49)
@@ -88,5 +88,5 @@
     bool divremcoefft( InternalCF*, InternalCF*&, InternalCF*&, bool );
 
-    int intval() const;
+    long intval() const;
 
     int intmod( int p ) const;
Index: factory/int_rat.cc
===================================================================
--- factory/int_rat.cc	(revision 1bc7201c1a771fb5cc842ca4f475ba3ea91e6979)
+++ factory/int_rat.cc	(revision c879eea1669e963fb4c7287a3963abb287d00a49)
@@ -29,4 +29,20 @@
 }
 
+static long intgcd( long a, long b )
+{
+    if ( a < 0 ) a = -a;
+    if ( b < 0 ) b = -b;
+
+    long c;
+
+    while ( b != 0 )
+    {
+        c = a % b;
+        a = b;
+        b = c;
+    }
+    return a;
+}
+
 
 InternalRational::InternalRational()
@@ -53,4 +69,34 @@
     {
         int g = intgcd( n, d );
+        if ( d < 0 )
+        {
+          mpz_init_set_si( _num, -n / g );
+          mpz_init_set_si( _den, -d / g );
+        }
+        else
+        {
+          mpz_init_set_si( _num, n / g );
+          mpz_init_set_si( _den, d / g );
+        }
+    }
+}
+
+InternalRational::InternalRational( const long i )
+{
+    mpz_init_set_si( _num, i );
+    mpz_init_set_si( _den, 1 );
+}
+
+InternalRational::InternalRational( const long n, const long d )
+{
+    ASSERT( d != 0, "divide by zero" );
+    if ( n == 0 )
+    {
+        mpz_init_set_si( _num, 0 );
+        mpz_init_set_si( _den, 1 );
+    }
+    else
+    {
+        long g = intgcd( n, d );
         if ( d < 0 )
         {
@@ -378,5 +424,5 @@
     {
         if ( deleteObject() ) delete this;
-        return CFFactory::basic( 1 );
+        return CFFactory::basic( 1L );
     }
     else
@@ -449,5 +495,5 @@
 {
     if ( deleteObject() ) delete this;
-    return CFFactory::basic( 0 );
+    return CFFactory::basic( 0L );
 }
 
@@ -456,5 +502,5 @@
     quot = copyObject();
     quot = quot->dividesame( c );
-    rem = CFFactory::basic( 0 );
+    rem = CFFactory::basic( 0L );
 }
 
@@ -528,5 +574,5 @@
     if ( ::is_imm( c ) )
     {
-        int cc = imm2int( c );
+        long cc = imm2int( c );
         if ( cc == 0 )
             return this;
@@ -565,5 +611,5 @@
     if ( ::is_imm( c ) )
     {
-        int cc = imm2int( c );
+        long cc = imm2int( c );
         if ( cc == 0 )
         {
@@ -622,9 +668,9 @@
     if ( ::is_imm( c ) )
     {
-        int cc = imm2int( c );
+        long cc = imm2int( c );
         if ( cc == 0 )
         {
             if ( deleteObject() ) delete this;
-            return CFFactory::basic( 0 );
+            return CFFactory::basic( 0L );
         }
         mpz_init_set_si( n, cc );
@@ -675,5 +721,5 @@
     if ( ::is_imm( c ) )
     {
-        int cc = imm2int( c );
+        long cc = imm2int( c );
         ASSERT( c != 0 || invert, "divide by zero" );
         if ( cc == 0 )
@@ -681,5 +727,5 @@
             // => invert
             if ( deleteObject() ) delete this;
-            return CFFactory::basic( 0 );
+            return CFFactory::basic( 0L );
         }
         if ( invert )
@@ -764,5 +810,5 @@
     ASSERT( invert || ! ::is_imm( c ) || imm2int( c ) != 0, "divide by zero" );
     if ( deleteObject() ) delete this;
-    return CFFactory::basic( 0 );
+    return CFFactory::basic( 0L );
 }
 
@@ -771,5 +817,5 @@
     quot = copyObject();
     quot = quot->dividecoeff( c, invert );
-    rem = CFFactory::basic( 0 );
+    rem = CFFactory::basic( 0L );
 }
 
@@ -851,8 +897,10 @@
 
 
-int InternalRational::intval() const
-{
+long InternalRational::intval() const
+{
+
     ASSERT( mpz_cmp_si( _den, 1 ) == 0, "illegal operation" );
-    return (int)mpz_get_si( _num );
+    return mpz_get_si( _num );
+
 }
 
Index: factory/int_rat.h
===================================================================
--- factory/int_rat.h	(revision 1bc7201c1a771fb5cc842ca4f475ba3ea91e6979)
+++ factory/int_rat.h	(revision c879eea1669e963fb4c7287a3963abb287d00a49)
@@ -40,4 +40,6 @@
     InternalRational( const int i );
     InternalRational( const int n, const int d );
+    InternalRational( const long i );
+    InternalRational( const long n, const long d );
     InternalRational( const char * str );
     InternalRational( const mpz_ptr );
@@ -90,5 +92,5 @@
     InternalCF * bextgcdcoeff ( InternalCF *, CanonicalForm &, CanonicalForm & );
 
-    int intval() const;
+    long intval() const;
 
     int sign() const;
Index: libpolys/coeffs/longrat.cc
===================================================================
--- libpolys/coeffs/longrat.cc	(revision 1bc7201c1a771fb5cc842ca4f475ba3ea91e6979)
+++ libpolys/coeffs/longrat.cc	(revision c879eea1669e963fb4c7287a3963abb287d00a49)
@@ -267,6 +267,11 @@
     {
       mpz_t dummy;
-      mpz_init_set( dummy,n->z );
-      term = make_cf( dummy );
+      long lz=mpz_get_si(n->z);
+      if (mpz_cmp_si(n->z,lz)==0) term=lz;
+      else
+      {
+        mpz_init_set( dummy,n->z );
+        term = make_cf( dummy );
+      }
     }
     else
@@ -287,4 +292,11 @@
   if (n.isImm())
   {
+    long lz=n.intval();
+    int iz=(int)lz;
+    if ((long)iz==lz)
+    {
+      return nlInit(n.intval(),r);
+    }
+    else  return nlRInit(lz);
     return nlInit(n.intval(),r);
   }
Index: libpolys/polys/clapconv.cc
===================================================================
--- libpolys/polys/clapconv.cc	(revision 1bc7201c1a771fb5cc842ca4f475ba3ea91e6979)
+++ libpolys/polys/clapconv.cc	(revision c879eea1669e963fb4c7287a3963abb287d00a49)
@@ -245,5 +245,14 @@
 {
   if ( f.isImm() )
-    return n_Init( f.intval(), r->cf->extRing->cf);
+  {
+    long longf=f.intval();
+    int intf=(int) longf;
+    if((long)intf==longf)
+    {
+      assume (r->cf->extRing != NULL);
+      return n_Init(f.intval(),r->cf->extRing->cf);
+    }
+    else return nlRInit( longf );
+  }
   else
   {
