public void divideDestructiveNativeDecimal128(Decimal128 right, short newScale,
      Decimal128 remainder) {
    if (right.signum == 0) {
      SqlMathUtil.throwZeroDivisionException();
    }
    if (this.signum == 0) {
      this.scale = newScale;
      remainder.update(this);
      return;
    }

    // this = this.mag / 10**this.scale
    // right = right.mag / 10**right.scale
    // this / right = (this.mag / right.mag) / 10**(this.scale -
    // right.scale)
    // so, we need to scale down (this.scale - right.scale - newScale)
    short scaleBack = (short) (this.scale - right.scale - newScale);
    if (scaleBack >= 0) {

      // it's easier then because we simply do division and then scale
      // down.
      this.unscaledValue.divideDestructive(right.unscaledValue,
          remainder.unscaledValue);
      this.unscaledValue.scaleDownTenDestructive(scaleBack);
      remainder.unscaledValue.scaleDownTenDestructive(scaleBack);
    } else {

      // in this case, we have to scale up _BEFORE_ division. otherwise we
      // might lose precision. this is costly, but inevitable.
      this.unscaledValue.divideScaleUpTenDestructive(right.unscaledValue,
          (short) -scaleBack, remainder.unscaledValue);
    }

    this.scale = newScale;
    this.signum = (byte) (this.unscaledValue.isZero() ? 0
        : (this.signum * right.signum));
    remainder.scale = scale;
    remainder.signum = (byte) (remainder.unscaledValue.isZero() ? 0 : 1); // remainder
                                                                          // is
                                                                          // always
                                                                          // positive

    this.unscaledValue.throwIfExceedsTenToThirtyEight();
  }
As of 1/20/2014 this has a known bug in division. See
TestDecimal128.testKnownPriorErrors(). Keeping this source
code available since eventually it is better to fix this.
The fix employed now is to replace this code with code that
uses Java BigDecimal divide.

Performs division, changing the scale of this object to the specified
value.
<p>
Unchecked exceptions: ArithmeticException an invalid scale is specified or
overflow.
</p>

@param right
         right operand. this object is not modified.
@param newScale
         scale of the result. must be 0 or positive.
@param remainder
         object to receive remainder
common/src/java/org/apache/hadoop/hive/common/type/Decimal128.java