=================================================================== RCS file: /home/cvs/OpenXM_contrib/pari-2.2/src/kernel/none/Attic/level1.h,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -u -p -r1.1.1.1 -r1.2 --- OpenXM_contrib/pari-2.2/src/kernel/none/Attic/level1.h 2001/10/02 11:17:08 1.1.1.1 +++ OpenXM_contrib/pari-2.2/src/kernel/none/Attic/level1.h 2002/09/11 07:27:00 1.2 @@ -1,4 +1,4 @@ -/* $Id: level1.h,v 1.1.1.1 2001/10/02 11:17:08 noro Exp $ +/* $Id: level1.h,v 1.2 2002/09/11 07:27:00 noro Exp $ Copyright (C) 2000 The PARI group. @@ -33,6 +33,7 @@ long addssmod(long a, long b, long p); void addssz(long x, long y, GEN z); void affii(GEN x, GEN y); void affsi(long s, GEN x); +void affui(long s, GEN x); void affsr(long s, GEN x); GEN cgetg(long x, long y); GEN cgeti(long x); @@ -62,7 +63,9 @@ long expi(GEN x); double gtodouble(GEN x); GEN icopy(GEN x); GEN icopy_av(GEN x, GEN y); +GEN itor(GEN x, long prec); long itos(GEN x); +ulong itou(GEN x); GEN modis(GEN x, long y); GEN mpabs(GEN x); GEN mpadd(GEN x, GEN y); @@ -81,11 +84,13 @@ void mulssz(long x, long y, GEN z); GEN new_chunk(long x); GEN realun(long prec); GEN realzero(long prec); +GEN realzero_bit(long bitprec); void resiiz(GEN x, GEN y, GEN z); GEN resis(GEN x, long y); GEN ressi(long x, GEN y); GEN shiftr(GEN x, long n); long smodis(GEN x, long y); +GEN stor(long x, long prec); GEN stoi(long x); GEN subii(GEN x, GEN y); GEN subir(GEN x, GEN y); @@ -102,20 +107,20 @@ INLINE long evallg(long x) { if (x & ~LGBITS) err(errlg); - return m_evallg(x); + return _evallg(x); } INLINE long evallgef(long x) { if (x & ~LGEFBITS) err(errlgef); - return m_evallgef(x); + return _evallgef(x); } INLINE long evalvalp(long x) { - const long v = m_evalvalp(x); + const long v = _evalvalp(x); if (v & ~VALPBITS) err(errvalp); return v; } @@ -123,7 +128,7 @@ evalvalp(long x) INLINE long evalexpo(long x) { - const long v = m_evalexpo(x); + const long v = _evalexpo(x); if (v & ~EXPOBITS) err(errexpo); return v; } @@ -139,7 +144,7 @@ new_chunk(long x) #ifdef _WIN32 if (win32ctrlc) dowin32ctrlc(); #endif - avma = (long)z; return z; + avma = (gpmem_t)z; return z; } /* THE FOLLOWING ONES ARE IN mp.s */ @@ -219,7 +224,7 @@ mpabs(GEN x) INLINE long smodis(GEN x, long y) { - const long av=avma; divis(x,y); avma=av; + const gpmem_t av=avma; divis(x,y); avma=av; if (!hiremainder) return 0; return (signe(x)>0) ? hiremainder: labs(y)+hiremainder; } @@ -260,13 +265,12 @@ stoi(long x) INLINE long itos(GEN x) { - const long s=signe(x); - long p1; + const long s = signe(x); + long u; if (!s) return 0; - if (lgefint(x)>3) err(affer2); - p1=x[2]; if (p1 < 0) err(affer2); - return (s>0) ? p1 : -(long)p1; + u = (long)x[2]; if (lgefint(x) > 3 || u < 0) err(affer2); + return (s>0) ? u : -u; } INLINE void @@ -282,10 +286,13 @@ affii(GEN x, GEN y) INLINE void affsi(long s, GEN x) { - if (!s) { x[1]=2; return; } - if (lg(x)<3) err(affer1); - if (s>0) { x[1] = evalsigne(1) | evallgefint(3); x[2] = s; } - else { x[1] = evalsigne(-1) | evallgefint(3); x[2] = -s; } + if (!s) x[1] = evalsigne(0) | evallgefint(2); + else + { + if (lg(x) < 3) err(affer1); + if (s > 0) { x[1] = evalsigne( 1) | evallgefint(3); x[2] = s; } + else { x[1] = evalsigne(-1) | evallgefint(3); x[2] = -s; } + } } INLINE void @@ -295,8 +302,8 @@ affsr(long s, GEN x) if (!s) { - l = -bit_accuracy(lg(x)); - x[1]=evalexpo(l); x[2]=0; return; + x[1] = evalexpo(-bit_accuracy(lg(x))); + return; } if (s<0) { x[1] = evalsigne(-1); s = -s; } else x[1] = evalsigne(1); @@ -326,10 +333,11 @@ shiftr(GEN x, long n) INLINE int cmpir(GEN x, GEN y) { - long av; + gpmem_t av; GEN z; if (!signe(x)) return -signe(y); + if (!signe(y)) return signe(x); av=avma; z=cgetr(lg(y)); affir(x,z); avma=av; return cmprr(z,y); /* cmprr does no memory adjustment */ } @@ -337,7 +345,7 @@ cmpir(GEN x, GEN y) INLINE int cmpsr(long x, GEN y) { - long av; + gpmem_t av; GEN z; if (!x) return -signe(y); @@ -351,7 +359,7 @@ addssz(long x, long y, GEN z) if (typ(z)==t_INT) gops2ssz(addss,x,y,z); else { - const long av=avma; + const gpmem_t av=avma; const GEN p1=cgetr(lg(z)); affsr(x,p1); affrr(addrs(p1,y),z); avma=av; @@ -426,7 +434,7 @@ mulssz(long x, long y, GEN z) if (typ(z)==t_INT) gops2ssz(mulss,x,y,z); else { - const long av=avma; + const gpmem_t av=avma; const GEN p1=cgetr(lg(z)); affsr(x,p1); mpaff(mulsr(y,p1),z); avma=av; @@ -436,21 +444,21 @@ mulssz(long x, long y, GEN z) INLINE void mulsii(long x, GEN y, GEN z) { - const long av=avma; + const gpmem_t av=avma; affii(mulsi(x,y),z); avma=av; } INLINE void addsii(long x, GEN y, GEN z) { - const long av=avma; + const gpmem_t av=avma; affii(addsi(x,y),z); avma=av; } INLINE long divisii(GEN x, long y, GEN z) { - const long av=avma; + const gpmem_t av=avma; affii(divis(x,y),z); avma=av; return hiremainder; } @@ -501,7 +509,7 @@ dvmdis(GEN x, long y, GEN *z) INLINE void dvmdssz(long x, long y, GEN z, GEN t) { - const long av=avma; + const gpmem_t av=avma; const GEN p1=divss(x,y); affsi(hiremainder,t); mpaff(p1,z); avma=av; @@ -510,7 +518,7 @@ dvmdssz(long x, long y, GEN z, GEN t) INLINE void dvmdsiz(long x, GEN y, GEN z, GEN t) { - const long av=avma; + const gpmem_t av=avma; const GEN p1=divsi(x,y); affsi(hiremainder,t); mpaff(p1,z); avma=av; @@ -519,7 +527,7 @@ dvmdsiz(long x, GEN y, GEN z, GEN t) INLINE void dvmdisz(GEN x, long y, GEN z, GEN t) { - const long av=avma; + const gpmem_t av=avma; const GEN p1=divis(x,y); affsi(hiremainder,t); mpaff(p1,z); avma=av; @@ -528,7 +536,7 @@ dvmdisz(GEN x, long y, GEN z, GEN t) INLINE void dvmdiiz(GEN x, GEN y, GEN z, GEN t) { - const long av=avma; + const gpmem_t av=avma; GEN p; mpaff(dvmdii(x,y,&p),z); mpaff(p,t); avma=av; @@ -543,14 +551,14 @@ modis(GEN x, long y) INLINE GEN ressi(long x, GEN y) { - const long av=avma; + const gpmem_t av=avma; divsi(x,y); avma=av; return stoi(hiremainder); } INLINE GEN resis(GEN x, long y) { - const long av=avma; + const gpmem_t av=avma; divis(x,y); avma=av; return stoi(hiremainder); } @@ -560,7 +568,7 @@ divisz(GEN x, long y, GEN z) if (typ(z)==t_INT) gops2gsz(divis,x,y,z); else { - const long av=avma; + const gpmem_t av=avma; const GEN p1=cgetr(lg(z)); affir(x,p1); affrr(divrs(p1,y),z); avma=av; @@ -570,7 +578,7 @@ divisz(GEN x, long y, GEN z) INLINE void divsiz(long x, GEN y, GEN z) { - const long av=avma; + const gpmem_t av=avma; if (typ(z)==t_INT) gaffect(divsi(x,y),z); else @@ -587,7 +595,7 @@ divsiz(long x, GEN y, GEN z) INLINE void divssz(long x, long y, GEN z) { - const long av=avma; + const gpmem_t av=avma; if (typ(z)==t_INT) gaffect(divss(x,y),z); else @@ -602,21 +610,21 @@ divssz(long x, long y, GEN z) INLINE void divrrz(GEN x, GEN y, GEN z) { - const long av=avma; + const gpmem_t av=avma; mpaff(divrr(x,y),z); avma=av; } INLINE void resiiz(GEN x, GEN y, GEN z) { - const long av=avma; + const gpmem_t av=avma; affii(resii(x,y),z); avma=av; } INLINE int divise(GEN x, GEN y) { - const long av=avma; + const gpmem_t av=avma; const GEN p1=resii(x,y); avma=av; return p1 == gzero; } @@ -664,7 +672,7 @@ mpdiv(GEN x, GEN y) INLINE int mpdivis(GEN x, GEN y, GEN z) { - const long av=avma; + const gpmem_t av=avma; GEN p2; const GEN p1=dvmdii(x,y,&p2); @@ -675,10 +683,31 @@ mpdivis(GEN x, GEN y, GEN z) /* THE FOLLOWING ONES ARE NOT IN mp.s */ # endif /* !defined(__M68K__) */ +INLINE ulong +itou(GEN x) +{ + const long s = signe(x); + + if (!s) return 0; + if (lgefint(x) > 3) err(affer2); + return x[2]; +} + +INLINE void +affui(ulong u, GEN x) +{ + if (!u) x[1] = evalsigne(0) | evallgefint(2); + else + { + if (lg(x) < 3) err(affer1); + x[1] = evalsigne(1) | evallgefint(3); x[2] = u; + } +} + INLINE int mpdivisis(GEN x, long y, GEN z) { - const ulong av = avma; + const gpmem_t av = avma; GEN p1 = divis(x,y); if (hiremainder) { avma = av; return 0; } affii(p1,z); avma = av; return 1; @@ -687,26 +716,26 @@ mpdivisis(GEN x, long y, GEN z) INLINE double gtodouble(GEN x) { - static long reel4[4]={ evaltyp(t_REAL) | m_evallg(4),0,0,0 }; + static long reel4[4]={ evaltyp(t_REAL) | _evallg(4),0,0,0 }; if (typ(x)==t_REAL) return rtodbl(x); gaffect(x,(GEN)reel4); return rtodbl((GEN)reel4); } INLINE GEN -realzero(long prec) -{ - GEN x=cgetr(3); - x[1]=evalexpo(-bit_accuracy(prec)); - x[2]=0; return x; -} +realzero_bit(long bitprec) { GEN x=cgetr(2); x[1]=evalexpo(bitprec); return x; } INLINE GEN -realun(long prec) -{ - GEN x=cgetr(prec); affsr(1,x); - return x; -} +realzero(long prec) { return realzero_bit(-bit_accuracy(prec)); } + +INLINE GEN +realun(long prec) { GEN x=cgetr(prec); affsr(1,x); return x; } + +INLINE GEN +stor(long s, long prec) { GEN z = cgetr(prec); affsr(s,z); return z; } + +INLINE GEN +itor(GEN x, long prec) { GEN z = cgetr(prec); affir(x,z); return z; } INLINE long addssmod(long a, long b, long p)