private static BigDecimal enforcePrecisionScale(BigDecimal bd, int maxPrecision, int maxScale) {
    if (bd == null) {
      return null;
    }

    /**
     * Specially handling the case that bd=0, and we are converting it to a type where precision=scale,
     * such as decimal(1, 1).
     */
    if (bd.compareTo(BigDecimal.ZERO) == 0 && bd.scale() == 0 && maxPrecision == maxScale) {
      return bd.setScale(maxScale);
    }

    bd = trim(bd);

    if (bd.scale() > maxScale) {
      bd = bd.setScale(maxScale, RoundingMode.HALF_UP);
    }

    int maxIntDigits = maxPrecision - maxScale;
    int intDigits = bd.precision() - bd.scale();
    if (intDigits > maxIntDigits) {
      return null;
    }

    return bd;
  }
Get the sign of the underlying decimal.
@return 0 if the decimal is equal to 0, -1 if less than zero, and 1 if greater than 0
storage-api/src/java/org/apache/hadoop/hive/common/type/HiveDecimalV1.java