bridge/class-master/depend/pari/src/basemath/base3.c
/* Compute z^n in nf, left-shift binary powering */
Compute z^n in nf, left-shift binary powering
Compute z^n in nf left - shift binary powering
GEN
nfpow(GEN nf, GEN z, GEN n)
{
  pari_sp av = avma;
  long s;
  GEN x, cx;
  if (typ(n)!=t_INT) pari_err_TYPE("nfpow",n);
  nf = checknf(nf);
  s = signe(n); if (!s) return gen_1;
  x = nf_to_scalar_or_basis(nf, z);
  if (typ(x) != t_COL) return powgi(x,n);
  if (s < 0)
  { 
    GEN d;
    x = Q_remove_denom(x, &d);
    x = zk_inv(nf, x);
    x = primitive_part(x, &cx);
    cx = mul_content(cx, d);
    n = negi(n);
  }
  else
    x = primitive_part(x, &cx);
  x = gen_pow(x, n, (void*)nf, _sqr, _mul);
  if (cx) x = gmul(x, powgi(cx, n));
  return av==avma? gcopy(x): gerepileupto(av,x);
}
GEN nfpow ( GEN nf , GEN z , GEN n ) { pari_sp av = avma ; long s ; GEN x , cx ; if ( typ ( n ) != t_INT ) pari_err_TYPE ( " " , n ) ; nf = checknf ( nf ) ; s = signe ( n ) ; if ( ! s ) return gen_1 ; x = nf_to_scalar_or_basis ( nf , z ) ; if ( typ ( x ) != t_COL ) return powgi ( x , n ) ; if ( s < 0 ) { GEN d ; x = Q_remove_denom ( x , & d ) ; x = zk_inv ( nf , x ) ; x = primitive_part ( x , & cx ) ; cx = mul_content ( cx , d ) ; n = negi ( n ) ; } else x = primitive_part ( x , & cx ) ; x = gen_pow ( x , n , ( void * ) nf , _sqr , _mul ) ; if ( cx ) x = gmul ( x , powgi ( cx , n ) ) ; return av == avma ? gcopy ( x ) : gerepileupto ( av , x ) ; }
Compute z^n in nf, left-shift binary powering
Compute z^n in nf left - shift binary powering
/* simplified nfinv */