public static void doFastScaleDown(
      long fast0, long fast1, long fast2,
      int scaleDown,
      FastHiveDecimal fastResult) {

    // Adjust all longs using power 10 division/remainder.
    long result0;
    long result1;
    long result2;
    if (scaleDown < LONGWORD_DECIMAL_DIGITS) {

      // Part of lowest word survives.

      final long divideFactor = powerOfTenTable[scaleDown];
      final long multiplyFactor = powerOfTenTable[LONGWORD_DECIMAL_DIGITS - scaleDown];

      result0 =
          fast0 / divideFactor
        + ((fast1 % divideFactor) * multiplyFactor);
      result1 =
          fast1 / divideFactor
        + ((fast2 % divideFactor) * multiplyFactor);
      result2 =
          fast2 / divideFactor;

    } else if (scaleDown < TWO_X_LONGWORD_DECIMAL_DIGITS) {

      // Throw away lowest word.

      final int adjustedScaleDown = scaleDown - LONGWORD_DECIMAL_DIGITS;

      final long divideFactor = powerOfTenTable[adjustedScaleDown];
      final long multiplyFactor = powerOfTenTable[LONGWORD_DECIMAL_DIGITS - adjustedScaleDown];

      result0 =
          fast1 / divideFactor
        + ((fast2 % divideFactor) * multiplyFactor);
      result1 =
          fast2 / divideFactor;
      result2 = 0;

    } else {

      // Throw away middle and lowest words.

      final int adjustedScaleDown = scaleDown - 2*LONGWORD_DECIMAL_DIGITS;

      result0 =
          fast2 / powerOfTenTable[adjustedScaleDown];
      result1 = 0;
      result2 = 0;

    }

    if (result0 == 0 && result1 == 0 && result2 == 0) {
      fastResult.fastSignum = 0;
    }
    fastResult.fast0 = result0;
    fastResult.fast1 = result1;
    fastResult.fast2 = result2;
  }
*********************************************************************************************
  // Decimal Scale Up/Down.

  /**
Fast decimal scale down by factor of 10 with NO rounding.

The signum will be updated if the result is 0, otherwise the original sign is unchanged.

@param fast0 word 0 of the internal representation
@param fast1 word 1
@param fast2 word 2
@param scaleDown the number of integer digits to scale
@param fastResult an object to reuse
storage-api/src/java/org/apache/hadoop/hive/common/type/FastHiveDecimalImpl.java