BigInteger quot = new BigInteger(); divide(this, val, quot, null, TRUNCATE); return quot.canonicalize();
if (y < 0) { yNegative = true; if (y == Long.MIN_VALUE) { if (rounding_mode == TRUNCATE) { if (quotient != null) quotient.set(0); if (remainder != null) remainder.set(x); } else divide(valueOf(x), valueOf(y), quotient, remainder, rounding_mode); return; } y = -y; } else yNegative = false;  long q = x / y; long r = x % y; boolean qNegative = xNegative ^ yNegative;  boolean add_one = false; if (r != 0) { switch (rounding_mode) { case TRUNCATE: break; case CEILING: case FLOOR: if (qNegative == (rounding_mode == FLOOR)) add_one = true; break; case ROUND: add_one = r > ((y - (q & 1)) >> 1); break; } } if (quotient != null) { if (add_one) q++; if (qNegative) q = -q; quotient.set(q); } if (remainder != null) {  if (add_one) {  r = y - r;   xNegative = ! xNegative; } else {   } if (xNegative) r = -r; remainder.set(r); }
  public BigInteger divide(BigInteger val)  {    if (val.isZero())      throw new ArithmeticException("divisor is zero");    BigInteger quot = new BigInteger();    divide(this, val, quot, null, TRUNCATE);    return quot.canonicalize();  }