| Michael Stoll on Mon, 20 Apr 1998 20:45:27 +0200 |
[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]
| A new varaint for gtrunc on padics |
The following is a little bit cleaner (and more efficient in the
case that we have a p-adic unit). Patch is with respect to the
original pari-2.0.7.alpha source). (GN: Is this OK?)
Michael
lordly:/Users/micha/UnixProjects/pari/pari-2.0.7.alpha> diff -c2
src/basemath/gen3.c.orig src/basemath/gen3.c
*** src/basemath/gen3.c.orig Sun Apr 19 15:33:15 1998
--- src/basemath/gen3.c Mon Apr 20 19:47:33 1998
***************
*** 1699,1703 ****
gtrunc(GEN x)
{
! long tx=typ(x),av,tetpil,i;
GEN y;
--- 1699,1703 ----
gtrunc(GEN x)
{
! long tx=typ(x),av,tetpil,i,v;
GEN y;
***************
*** 1715,1720 ****
case t_PADIC:
if (!signe(x[4])) return gzero;
! av=avma; y=gpuigs((GEN)x[2],valp(x)); tetpil=avma;
! return gerepile(av,tetpil, mulii(y,(GEN)x[4]));
case t_RFRAC: case t_RFRACN:
--- 1715,1733 ----
case t_PADIC:
if (!signe(x[4])) return gzero;
! v=valp(x);
! if (v==0) return (GEN)x[4]; /* simplest case */
! if (v>0)
! { /* here, p^v is an integer, so we can use mulii */
! av=avma; y=gpuigs((GEN)x[2],v); tetpil=avma;
! return gerepile(av,tetpil,mulii(y,(GEN)x[4]));
! }
! else
! { /* result is the fraction x[4]/p^(-v);
! should already be in lowest terms */
! y=cgetg(3,t_FRAC);
! y[1]=lcopy((GEN)x[4]);
! y[2]=lpuigs((GEN)x[2],-v);
! return y;
! }
case t_RFRAC: case t_RFRACN: