public BigDecimal divide(BigDecimal val, int newScale, int roundingMode)
public BigDecimal divide (BigDecimal val, int roundingMode)
  public BigDecimal divide(BigDecimal val, int newScale, int roundingMode)    throws ArithmeticException, IllegalArgumentException   {    if (roundingMode < 0 || roundingMode > 7)      throw 	new IllegalArgumentException("illegal rounding mode: " + roundingMode);    if (newScale < 0)      throw new ArithmeticException ("scale is negative: " + newScale);    if (intVal.signum () == 0)	// handle special case of 0.0/0.0      return ZERO;        // Ensure that pow gets a non-negative value.    int valScale = val.scale;    BigInteger valIntVal = val.intVal;    int power = newScale + 1 - (scale - val.scale);    if (power < 0)      {	// Effectively increase the scale of val to avoid an	// ArithmeticException for a negative power.        valIntVal = valIntVal.multiply (BigInteger.valueOf (10).pow (-power));	power = 0;      }    BigInteger dividend = intVal.multiply (BigInteger.valueOf (10).pow (power));        BigInteger parts[] = dividend.divideAndRemainder (valIntVal);//      System.out.println("int: " + parts[0]);//      System.out.println("rem: " + parts[1]);    int roundDigit = parts[0].mod (BigInteger.valueOf (10)).intValue ();    BigInteger unrounded = parts[0].divide (BigInteger.valueOf (10));    if (roundDigit == 0 && parts[1].signum () == 0) // no rounding necessary      return new BigDecimal (unrounded, newScale);    int sign = unrounded.signum ();    switch (roundingMode)      {      case ROUND_UNNECESSARY:	throw new ArithmeticException ("newScale is not large enough");      case ROUND_CEILING:	roundingMode = (sign == 1) ? ROUND_UP : ROUND_DOWN;	break;      case ROUND_FLOOR:	roundingMode = (sign == 1) ? ROUND_DOWN : ROUND_UP;	break;      case ROUND_HALF_UP:	roundingMode = (roundDigit >= 5) ? ROUND_UP : ROUND_DOWN;	break;      case ROUND_HALF_DOWN:	roundingMode = (roundDigit > 5) ? ROUND_UP : ROUND_DOWN;	break;      case ROUND_HALF_EVEN:	if (roundDigit < 5)	  roundingMode = ROUND_DOWN;	else	  {	    int rightmost = 	      unrounded.mod (BigInteger.valueOf (10)).intValue ();	    if (rightmost % 2 == 1) // odd, then ROUND_HALF_UP	      roundingMode = ROUND_UP;	    else // even, then ROUND_HALF_DOWN	      roundingMode = (roundDigit > 5) ? ROUND_UP : ROUND_DOWN;	  }	break;      }    if (roundingMode == ROUND_UP)      return new BigDecimal (unrounded.add (BigInteger.valueOf (1)), newScale);    // roundingMode == ROUND_DOWN    return new BigDecimal (unrounded, newScale);  }