bridge/class-master/depend/pari/src/kernel/gmp/mp.c
/* We keep llx bits of x and lly bits of y*/
We keep llx bits of x and lly bits of y
We keep llx bits of x and lly bits of y
static GEN
divrr_with_gmp(GEN x, GEN y)
{
  long lx=RNLIMBS(x),ly=RNLIMBS(y);
  long lw=minss(lx,ly);
  long lly=minss(lw+1,ly);
  GEN  w=cgetr(lw+2);
  long lu=lw+lly;
  long llx=minss(lu,lx);
  mp_limb_t *u=(mp_limb_t *)new_chunk(lu);
  mp_limb_t *z=(mp_limb_t *)new_chunk(lly);
  mp_limb_t *q,*r;
  long e=expo(x)-expo(y);
  long sx=signe(x),sy=signe(y);
  xmpn_mirrorcopy(z,RLIMBS(y),lly);
  xmpn_mirrorcopy(u+lu-llx,RLIMBS(x),llx);
  xmpn_zero(u,lu-llx);
  q = (mp_limb_t *)new_chunk(lw+1);
  r = (mp_limb_t *)new_chunk(lly);
  mpn_tdiv_qr(q,r,0,u,lu,z,lly);
  if (uel(r,lly-1) > (uel(z,lly-1)>>1))
    mpn_add_1(q,q,lw+1,1);
  xmpn_mirrorcopy(RLIMBS(w),q,lw);
  if (q[lw] == 0) e--;
  else if (q[lw] == 1) { shift_right(w,w, 2,lw+2, 1,1); }
  else { w[2] = HIGHBIT; e++; }
  if (sy < 0) sx = -sx;
  w[1] = evalsigne(sx) | evalexpo(e);
  avma=(pari_sp) w;
  return w;
}
static GEN divrr_with_gmp ( GEN x , GEN y ) { long lx = RNLIMBS ( x ) , ly = RNLIMBS ( y ) ; long lw = minss ( lx , ly ) ; long lly = minss ( lw + 1 , ly ) ; GEN w = cgetr ( lw + 2 ) ; long lu = lw + lly ; long llx = minss ( lu , lx ) ; mp_limb_t * u = ( mp_limb_t * ) new_chunk ( lu ) ; mp_limb_t * z = ( mp_limb_t * ) new_chunk ( lly ) ; mp_limb_t * q , * r ; long e = expo ( x ) - expo ( y ) ; long sx = signe ( x ) , sy = signe ( y ) ; xmpn_mirrorcopy ( z , RLIMBS ( y ) , lly ) ; xmpn_mirrorcopy ( u + lu - llx , RLIMBS ( x ) , llx ) ; xmpn_zero ( u , lu - llx ) ; q = ( mp_limb_t * ) new_chunk ( lw + 1 ) ; r = ( mp_limb_t * ) new_chunk ( lly ) ; mpn_tdiv_qr ( q , r , 0 , u , lu , z , lly ) ; if ( uel ( r , lly - 1 ) > ( uel ( z , lly - 1 ) >> 1 ) ) mpn_add_1 ( q , q , lw + 1 , 1 ) ; xmpn_mirrorcopy ( RLIMBS ( w ) , q , lw ) ; if ( q [ lw ] == 0 ) e -- ; else if ( q [ lw ] == 1 ) { shift_right ( w , w , 2 , lw + 2 , 1 , 1 ) ; } else { w [ 2 ] = HIGHBIT ; e ++ ; } if ( sy < 0 ) sx = - sx ; w [ 1 ] = evalsigne ( sx ) | evalexpo ( e ) ; avma = ( pari_sp ) w ; return w ; }
We keep llx bits of x and lly bits of y
We keep llx bits of x and lly bits of y
/*Round up: This is not exactly correct we should test 2*r>z*/