public static boolean fastSetFromBigInteger(
      BigInteger bigInteger, FastHiveDecimal fastResult) {

    final int signum = bigInteger.signum();
    if (signum == 0) {
      // Zero special case.
      return true;
    }
    fastResult.fastSignum = signum;
    if (signum == -1) {
      bigInteger = bigInteger.negate();
    }
    if (bigInteger.compareTo(BIG_INTEGER_LONGWORD_MULTIPLIER) < 0) {

      // Fits in one longword.
      fastResult.fast0 = bigInteger.longValue();
      if (fastResult.fast0 == 0) {
        fastResult.fastSignum = 0;
      } else {
        fastResult.fastIntegerDigitCount = fastLongWordPrecision(fastResult.fast0);
      }
      return true;
    }
    BigInteger[] quotientAndRemainder =
        bigInteger.divideAndRemainder(BIG_INTEGER_LONGWORD_MULTIPLIER);
    fastResult.fast0 = quotientAndRemainder[1].longValue();
    BigInteger quotient = quotientAndRemainder[0];
    if (quotient.compareTo(BIG_INTEGER_LONGWORD_MULTIPLIER) < 0) {

      // Fits in two longwords.
      fastResult.fast1 = quotient.longValue();
      if (fastResult.fast0 == 0 && fastResult.fast1 == 0) {
        // The special case zero logic at the beginning should have caught this.
        throw new RuntimeException("Unexpected");
      } else {
        fastResult.fastIntegerDigitCount =
            LONGWORD_DECIMAL_DIGITS + fastLongWordPrecision(fastResult.fast1);
      }
      return true;
    }

    // Uses all 3 decimal longs.
    quotientAndRemainder =
        quotient.divideAndRemainder(BIG_INTEGER_LONGWORD_MULTIPLIER);
    fastResult.fast1 = quotientAndRemainder[1].longValue();
    quotient = quotientAndRemainder[0];
    if (quotient.compareTo(BIG_INTEGER_HIGHWORD_MULTIPLIER) >= 0) {
      // Overflow.
      return false;
    }
    fastResult.fast2 = quotient.longValue();
    if (fastResult.fast0 == 0 && fastResult.fast1 == 0 && fastResult.fast2 == 0) {
      fastResult.fastSignum = 0;
    } else {
      fastResult.fastIntegerDigitCount =
          TWO_X_LONGWORD_DECIMAL_DIGITS + fastHighWordPrecision(fastResult.fast2);
    }
    return true;
  }
Creates a fast decimal from a BigInteger with scale 0.

For efficiency, we assume that fastResult is fastReset.  This method does not set the
fastScale field.

NOTE: The fastSetFromBigInteger method requires the caller to pass a fastResult
parameter has been reset for better performance.

@param bigInteger the value to set
@param fastResult an object to reuse
@return Return true if the BigInteger value fit within HiveDecimal.MAX_PRECISION.  Otherwise,
        false for overflow.
storage-api/src/java/org/apache/hadoop/hive/common/type/FastHiveDecimalImpl.java