bridge/class-master/depend/pari/src/basemath/gen2.c
/* normalize series. avma is not updated */
normalize series. avma is not updated
normalize series . avma is not updated
GEN
normalize(GEN x)
{
  long i, lx = lg(x), vx=varn(x), vp=valp(x);
  GEN y, z;
  if (typ(x) != t_SER) pari_err_TYPE("normalize",x);
  if (lx == 2) { setsigne(x,0); return x; }
  if (lx == 3) {
    z = gel(x,2);
    if (!gequal0(z)) { setsigne(x,1); return x; }
    if (isrationalzero(z)) return zeroser(vx,vp+1);
    if (isexactzero(z)) {
      if (!signe(x)) return x;
      setvalp(x,vp+1); 
    }
    setsigne(x,0); return x;
  }
  for (i=2; i<lx; i++)
    if (! isrationalzero(gel(x,i))) break;
  if (i == lx) return zeroser(vx,lx-2+vp);
  z = gel(x,i);
  while (i<lx && isexactzero(gel(x,i))) i++;
  if (i == lx)
  {
    i -= 3; y = x + i;
    stackdummy((pari_sp)y, (pari_sp)x);
    gel(y,2) = z;
    y[1] = evalsigne(0) | evalvalp(lx-2+vp) | evalvarn(vx);
    y[0] = evaltyp(t_SER) | _evallg(3);
    return y;
  }
  i -= 2; y = x + i; lx -= i;
  y[1] = evalsigne(1) | evalvalp(vp+i) | evalvarn(vx);
  y[0] = evaltyp(t_SER) | evallg(lx);
  stackdummy((pari_sp)y, (pari_sp)x);
  for (i = 2; i < lx; i++)
    if (!gequal0(gel(y, i))) return y;
  setsigne(y, 0); return y;
}
GEN normalize ( GEN x ) { long i , lx = lg ( x ) , vx = varn ( x ) , vp = valp ( x ) ; GEN y , z ; if ( typ ( x ) != t_SER ) pari_err_TYPE ( " " , x ) ; if ( lx == 2 ) { setsigne ( x , 0 ) ; return x ; } if ( lx == 3 ) { z = gel ( x , 2 ) ; if ( ! gequal0 ( z ) ) { setsigne ( x , 1 ) ; return x ; } if ( isrationalzero ( z ) ) return zeroser ( vx , vp + 1 ) ; if ( isexactzero ( z ) ) { if ( ! signe ( x ) ) return x ; setvalp ( x , vp + 1 ) ; } setsigne ( x , 0 ) ; return x ; } for ( i = 2 ; i < lx ; i ++ ) if ( ! isrationalzero ( gel ( x , i ) ) ) break ; if ( i == lx ) return zeroser ( vx , lx - 2 + vp ) ; z = gel ( x , i ) ; while ( i < lx && isexactzero ( gel ( x , i ) ) ) i ++ ; if ( i == lx ) { i -= 3 ; y = x + i ; stackdummy ( ( pari_sp ) y , ( pari_sp ) x ) ; gel ( y , 2 ) = z ; y [ 1 ] = evalsigne ( 0 ) | evalvalp ( lx - 2 + vp ) | evalvarn ( vx ) ; y [ 0 ] = evaltyp ( t_SER ) | _evallg ( 3 ) ; return y ; } i -= 2 ; y = x + i ; lx -= i ; y [ 1 ] = evalsigne ( 1 ) | evalvalp ( vp + i ) | evalvarn ( vx ) ; y [ 0 ] = evaltyp ( t_SER ) | evallg ( lx ) ; stackdummy ( ( pari_sp ) y , ( pari_sp ) x ) ; for ( i = 2 ; i < lx ; i ++ ) if ( ! gequal0 ( gel ( y , i ) ) ) return y ; setsigne ( y , 0 ) ; return y ; }
normalize series.
normalize series .
/* dangerous case: already normalized ? */ /* no: normalize */