private static boolean doAddDifferentScale(
      int leftSignum, long leftFast0, long leftFast1, long leftFast2,
      int leftIntegerDigitCount, int leftScale,
      int rightSignum, long rightFast0, long rightFast1, long rightFast2,
      int rightIntegerDigitCount, int rightScale,
      FastHiveDecimal fastResult) {

    if (leftSignum == rightSignum) {
      if (!fastAddDifferentScale(
          leftFast0, leftFast1, leftFast2,
          leftIntegerDigitCount, leftScale,
          rightFast0, rightFast1, rightFast2,
          rightIntegerDigitCount, rightScale,
          fastResult)) {
        return false;
      }
      // Sign stays the same.
      fastResult.fastSignum = leftSignum;
    } else {

      // Just compare the magnitudes (i.e. signums set to 1).
      int compareTo =
          fastCompareTo(
              1,
              leftFast0, leftFast1, leftFast2, leftScale,
              1,
              rightFast0, rightFast1, rightFast2, rightScale);
      if (compareTo == 0) {
        // They cancel each other.
        fastResult.fastSignum = 0;
        fastResult.fast0 = 0;
        fastResult.fast1 = 0;
        fastResult.fast2 = 0;
        fastResult.fastScale = 0;
        return true;
      }

      if (compareTo == 1) {
        if (!fastSubtractDifferentScale(
                leftFast0, leftFast1, leftFast2,
                leftIntegerDigitCount, leftScale,
                rightFast0, rightFast1, rightFast2,
                rightIntegerDigitCount, rightScale,
                fastResult)) {
          throw new RuntimeException("Unexpected overflow");
        }
        fastResult.fastSignum = leftSignum;
      } else {
        if (!fastSubtractDifferentScale(
                rightFast0, rightFast1, rightFast2,
                rightIntegerDigitCount, rightScale,
                leftFast0, leftFast1, leftFast2,
                leftIntegerDigitCount, leftScale,
                fastResult)) {
          throw new RuntimeException("Unexpected overflow");
        }
        fastResult.fastSignum = rightSignum;
      }
    }

    final int resultTrailingZeroCount =
        fastTrailingDecimalZeroCount(
            fastResult.fast0, fastResult.fast1, fastResult.fast2,
            fastResult.fastIntegerDigitCount, fastResult.fastScale);
    if (resultTrailingZeroCount > 0) {
      doFastScaleDown(
          fastResult,
          resultTrailingZeroCount,
          fastResult);
      if (fastResult.fastSignum == 0) {
        fastResult.fastScale = 0;
      } else {
        fastResult.fastScale -= resultTrailingZeroCount;
      }
    }

    return true;
  }
Handle decimal addition when the values have different scales.
storage-api/src/java/org/apache/hadoop/hive/common/type/FastHiveDecimalImpl.java