bridge/class-master/depend/pari/src/basemath/bb_group.c
/* assume n > 0. Compute x^n using left-right binary powering */
assume n > 0. Compute x^n using left-right binary powering
assume n > 0 . Compute x^n using left - right binary powering
GEN
gen_powu_fold_i(GEN x, ulong n, void *E, GEN  (*sqr)(void*,GEN),
                                         GEN (*msqr)(void*,GEN))
{
  pari_sp av = avma;
  GEN y;
  int j;
  if (n == 1) return x;
  y = x; j = 1+bfffo(n);
  n<<=j; j = BITS_IN_LONG-j;
  for (; j; n<<=1,j--)
  {
    if (n & HIGHBIT) y = msqr(E,y); 
    else y = sqr(E,y);
    if (gc_needed(av,1))
    {
      if (DEBUGMEM>1) pari_warn(warnmem,"gen_powu_fold (%d)", j);
      y = gerepilecopy(av, y);
    }
  }
  return y;
}
GEN gen_powu_fold_i ( GEN x , ulong n , void * E , GEN ( * sqr ) ( void * , GEN ) , GEN ( * msqr ) ( void * , GEN ) ) { pari_sp av = avma ; GEN y ; int j ; if ( n == 1 ) return x ; y = x ; j = 1 + bfffo ( n ) ; n <<= j ; j = BITS_IN_LONG - j ; for ( ; j ; n <<= 1 , j -- ) { if ( n & HIGHBIT ) y = msqr ( E , y ) ; else y = sqr ( E , y ) ; if ( gc_needed ( av , 1 ) ) { if ( DEBUGMEM > 1 ) pari_warn ( warnmem , " " , j ) ; y = gerepilecopy ( av , y ) ; } } return y ; }
assume n > 0.
assume n > 0 .
/* normalize, i.e set highest bit to 1 (we know n != 0) */ /* first bit is now implicit */ /* first bit set: multiply by base */