bridge/class-master/depend/pari/src/basemath/rootpol.c
/* returns the exponent for logmodulus(), from the Newton diagram */
returns the exponent for logmodulus(), from the Newton diagram
returns the exponent for logmodulus () from the Newton diagram
static long
newton_polygon(GEN p, long k)
{
  pari_sp av = avma;
  double *logcoef, slope;
  long n = degpol(p), i, j, h, l, *vertex;
  logcoef = (double*)stack_malloc_align((n+1)*sizeof(double), sizeof(double));
  vertex = (long*)new_chunk(n+1);
  for (i=0; i<=n; i++) { logcoef[i] = dbllog2(gel(p,2+i)); vertex[i] = 0; }
  vertex[0] = 1; 
  for (i=0; i < n; i=h)
  {
    slope = logcoef[i+1]-logcoef[i];
    for (j = h = i+1; j<=n; j++)
    {
      double pij = (logcoef[j]-logcoef[i])/(double)(j-i);
      if (slope < pij) { slope = pij; h = j; }
    }
    vertex[h] = 1;
  }
  h = k;   while (!vertex[h]) h++;
  l = k-1; while (!vertex[l]) l--;
  avma = av;
  return (long)floor((logcoef[h]-logcoef[l])/(double)(h-l) + 0.5);
}
static long newton_polygon ( GEN p , long k ) { pari_sp av = avma ; double * logcoef , slope ; long n = degpol ( p ) , i , j , h , l , * vertex ; logcoef = ( double * ) stack_malloc_align ( ( n + 1 ) * sizeof ( double ) , sizeof ( double ) ) ; vertex = ( long * ) new_chunk ( n + 1 ) ; for ( i = 0 ; i <= n ; i ++ ) { logcoef [ i ] = dbllog2 ( gel ( p , 2 + i ) ) ; vertex [ i ] = 0 ; } vertex [ 0 ] = 1 ; for ( i = 0 ; i < n ; i = h ) { slope = logcoef [ i + 1 ] - logcoef [ i ] ; for ( j = h = i + 1 ; j <= n ; j ++ ) { double pij = ( logcoef [ j ] - logcoef [ i ] ) / ( double ) ( j - i ) ; if ( slope < pij ) { slope = pij ; h = j ; } } vertex [ h ] = 1 ; } h = k ; while ( ! vertex [ h ] ) h ++ ; l = k - 1 ; while ( ! vertex [ l ] ) l -- ; avma = av ; return ( long ) floor ( ( logcoef [ h ] - logcoef [ l ] ) / ( double ) ( h - l ) + 0.5 ) ; }
returns the exponent for logmodulus(), from the Newton diagram
returns the exponent for logmodulus () from the Newton diagram
/* vertex[i] = 1 if i a vertex of convex hull, 0 otherwise */ /* sentinel */