public static boolean fastRoundIntegerDown(
      int fastSignum, long fast0, long fast1, long fast2,
      int fastIntegerDigitCount, int fastScale,
      int roundPower,
      FastHiveDecimal fastResult) {

    /*
     * Basic algorithm:
     *
     * 1. Scale away fractional digits if present.
     * 2. Clear integer rounding portion.
     *
     */

    if (roundPower >= 0) {
      throw new IllegalArgumentException("Expecting roundPower < 0 (roundPower " + roundPower + ")");
    }

    final int absRoundPower = -roundPower;
    if (fastIntegerDigitCount < absRoundPower) {

      // Zero result.
      fastResult.fastReset();
      return true;
    }

    final int roundingPoint = absRoundPower + fastScale;
    if (roundingPoint > HiveDecimal.MAX_PRECISION) {

      // Value becomes zero for rounding beyond.
      fastResult.fastReset();
      return true;
    }

    // If necessary, divide and multiply to get rid of fractional digits.
    if (fastScale == 0) {
      fastResult.fast0 = fast0;
      fastResult.fast1 = fast1;
      fastResult.fast2 = fast2;
    } else {
      doFastScaleDown(
          fast0, fast1, fast2,
          /* scaleDown */ fastScale,
          fastResult);
    }

    // The fractional digits are gone; clear remaining round digits.
    doClearRoundIntegerPortion(
        fastResult.fast0, fastResult.fast1, fastResult.fast2,
        absRoundPower,
        fastResult);

    if (fastResult.fast0 == 0 && fastResult.fast1 == 0 && fastResult.fast2 == 0) {
      fastResult.fastIntegerDigitCount = 0;
      fastResult.fastScale = 0;
    } else {
      fastResult.fastSignum = fastSignum;
      fastResult.fastIntegerDigitCount = fastRawPrecision(fastResult);
      fastResult.fastScale = 0;
    }

    return true;
  }
Fast decimal scale down by factor of 10 with rounding ROUND_DOWN.

The fraction being scaled away is thrown away.

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

@param fastSignum the sign (-1, 0, or +1)
@param fast0 word 0 of the internal representation
@param fast1 word 1
@param fast2 word 2
@param fastIntegerDigitCount the number of integer digits
@param fastScale the scale of the number
@param roundPower the power to round to
@param fastResult an object to reuse
@return was the operation successful?
storage-api/src/java/org/apache/hadoop/hive/common/type/FastHiveDecimalImpl.java