private MutableBigInteger divideLongMagnitude(long ldivisor,MutableBigInteger quotient){
  MutableBigInteger rem=new MutableBigInteger(new int[intLen + 1]);
  System.arraycopy(value,offset,rem.value,1,intLen);
  rem.intLen=intLen;
  rem.offset=1;
  int nlen=rem.intLen;
  int limit=nlen - 2 + 1;
  if (quotient.value.length < limit) {
    quotient.value=new int[limit];
    quotient.offset=0;
  }
  quotient.intLen=limit;
  int[] q=quotient.value;
  int shift=Long.numberOfLeadingZeros(ldivisor);
  if (shift > 0) {
    ldivisor<<=shift;
    rem.leftShift(shift);
  }
  if (rem.intLen == nlen) {
    rem.offset=0;
    rem.value[0]=0;
    rem.intLen++;
  }
  int dh=(int)(ldivisor >>> 32);
  long dhLong=dh & LONG_MASK;
  int dl=(int)(ldivisor & LONG_MASK);
  for (int j=0; j < limit; j++) {
    int qhat=0;
    int qrem=0;
    boolean skipCorrection=false;
    int nh=rem.value[j + rem.offset];
    int nh2=nh + 0x80000000;
    int nm=rem.value[j + 1 + rem.offset];
    if (nh == dh) {
      qhat=~0;
      qrem=nh + nm;
      skipCorrection=qrem + 0x80000000 < nh2;
    }
 else {
      long nChunk=(((long)nh) << 32) | (nm & LONG_MASK);
      if (nChunk >= 0) {
        qhat=(int)(nChunk / dhLong);
        qrem=(int)(nChunk - (qhat * dhLong));
      }
 else {
        long tmp=divWord(nChunk,dh);
        qhat=(int)(tmp & LONG_MASK);
        qrem=(int)(tmp >>> 32);
      }
    }
    if (qhat == 0)     continue;
    if (!skipCorrection) {
      long nl=rem.value[j + 2 + rem.offset] & LONG_MASK;
      long rs=((qrem & LONG_MASK) << 32) | nl;
      long estProduct=(dl & LONG_MASK) * (qhat & LONG_MASK);
      if (unsignedLongCompare(estProduct,rs)) {
        qhat--;
        qrem=(int)((qrem & LONG_MASK) + dhLong);
        if ((qrem & LONG_MASK) >= dhLong) {
          estProduct-=(dl & LONG_MASK);
          rs=((qrem & LONG_MASK) << 32) | nl;
          if (unsignedLongCompare(estProduct,rs))           qhat--;
        }
      }
    }
    rem.value[j + rem.offset]=0;
    int borrow=mulsubLong(rem.value,dh,dl,qhat,j + rem.offset);
    if (borrow + 0x80000000 > nh2) {
      divaddLong(dh,dl,rem.value,j + 1 + rem.offset);
      qhat--;
    }
    q[j]=qhat;
  }
  if (shift > 0)   rem.rightShift(shift);
  quotient.normalize();
  rem.normalize();
  return rem;
}

private MutableBigInteger divideLongMagnitude ( long ldivisor , MutableBigInteger quotient ) { MutableBigInteger rem = new MutableBigInteger ( new int [ intLen + 1 ] ) ; System . arraycopy ( value , offset , rem . value , 1 , intLen ) ; rem . intLen = intLen ; rem . offset = 1 ; int nlen = rem . intLen ; int limit = nlen - 2 + 1 ; if ( quotient . value . length < limit ) { quotient . value = new int [ limit ] ; quotient . offset = 0 ; } quotient . intLen = limit ; int [ ] q = quotient . value ; int shift = Long . numberOfLeadingZeros ( ldivisor ) ; if ( shift > 0 ) { ldivisor <<= shift ; rem . leftShift ( shift ) ; } if ( rem . intLen == nlen ) { rem . offset = 0 ; rem . value [ 0 ] = 0 ; rem . intLen ++ ; } int dh = ( int ) ( ldivisor > > > 32 ) ; long dhLong = dh & LONG_MASK ; int dl = ( int ) ( ldivisor & LONG_MASK ) ; for ( int j = 0 ; j < limit ; j ++ ) { int qhat = 0 ; int qrem = 0 ; boolean skipCorrection = false ; int nh = rem . value [ j + rem . offset ] ; int nh2 = nh + 0x80000000 ; int nm = rem . value [ j + 1 + rem . offset ] ; if ( nh == dh ) { qhat = ~ 0 ; qrem = nh + nm ; skipCorrection = qrem + 0x80000000 < nh2 ; } else { long nChunk = ( ( ( long ) nh ) << 32 ) | ( nm & LONG_MASK ) ; if ( nChunk >= 0 ) { qhat = ( int ) ( nChunk / dhLong ) ; qrem = ( int ) ( nChunk - ( qhat * dhLong ) ) ; } else { long tmp = divWord ( nChunk , dh ) ; qhat = ( int ) ( tmp & LONG_MASK ) ; qrem = ( int ) ( tmp > > > 32 ) ; } } if ( qhat == 0 ) continue ; if ( ! skipCorrection ) { long nl = rem . value [ j + 2 + rem . offset ] & LONG_MASK ; long rs = ( ( qrem & LONG_MASK ) << 32 ) | nl ; long estProduct = ( dl & LONG_MASK ) * ( qhat & LONG_MASK ) ; if ( unsignedLongCompare ( estProduct , rs ) ) { qhat -- ; qrem = ( int ) ( ( qrem & LONG_MASK ) + dhLong ) ; if ( ( qrem & LONG_MASK ) >= dhLong ) { estProduct -= ( dl & LONG_MASK ) ; rs = ( ( qrem & LONG_MASK ) << 32 ) | nl ; if ( unsignedLongCompare ( estProduct , rs ) ) qhat -- ; } } } rem . value [ j + rem . offset ] = 0 ; int borrow = mulsubLong ( rem . value , dh , dl , qhat , j + rem . offset ) ; if ( borrow + 0x80000000 > nh2 ) { divaddLong ( dh , dl , rem . value , j + 1 + rem . offset ) ; qhat -- ; } q [ j ] = qhat ; } if ( shift > 0 ) rem . rightShift ( shift ) ; quotient . normalize ( ) ; rem . normalize ( ) ; return rem ; }
divide this mutablebiginteger by the divisor represented by positive long value . the quotient will be placed into the provided quotient object & the remainder object is returned .
