public static boolean fastIsByte(
      int fastSignum, long fast0, long fast1, long fast2,
      int fastIntegerDigitCount, int fastScale) {

    if (fastIntegerDigitCount < MAX_BYTE_DIGITS) {

      // Definitely a byte; most bytes fall here
     return true;

    } else if (fastIntegerDigitCount > MAX_BYTE_DIGITS) {

      // Definitely not a byte.
      return false;

    } else if (fastScale == 0) {
      if (fast1 != 0 || fast2 != 0) {
        return false;
      }
      if (fastSignum == 1) {
        return (fast0 <= Byte.MAX_VALUE);
      } else {
        return (-fast0 >= Byte.MIN_VALUE);
      }
    } else {

      // We need to work a little harder for our comparison.  Note we round down for
      // integer conversion so anything below the next min/max will work.

      if (fastSignum == 1) {
        return
            (fastCompareTo(
                fastSignum, fast0, fast1, fast2, fastScale,
                FASTHIVEDECIMAL_MAX_BYTE_VALUE_PLUS_ONE) < 0);
      } else {
        return
            (fastCompareTo(
                fastSignum, fast0, fast1, fast2, fastScale,
                FASTHIVEDECIMAL_MIN_BYTE_VALUE_MINUS_ONE) > 0);
      }
    }
  }
*********************************************************************************************
  // Decimal to Integer conversion.

  private static final int MAX_BYTE_DIGITS = 3;
  private static final FastHiveDecimal FASTHIVEDECIMAL_MIN_BYTE_VALUE_MINUS_ONE =
      new FastHiveDecimal((long) Byte.MIN_VALUE - 1L);
  private static final FastHiveDecimal FASTHIVEDECIMAL_MAX_BYTE_VALUE_PLUS_ONE =
      new FastHiveDecimal((long) Byte.MAX_VALUE + 1L);

  private static final int MAX_SHORT_DIGITS = 5;
  private static final FastHiveDecimal FASTHIVEDECIMAL_MIN_SHORT_VALUE_MINUS_ONE =
      new FastHiveDecimal((long) Short.MIN_VALUE - 1L);
  private static final FastHiveDecimal FASTHIVEDECIMAL_MAX_SHORT_VALUE_PLUS_ONE =
      new FastHiveDecimal((long) Short.MAX_VALUE + 1L);

  private static final int MAX_INT_DIGITS = 10;
  private static final FastHiveDecimal FASTHIVEDECIMAL_MIN_INT_VALUE_MINUS_ONE =
      new FastHiveDecimal((long) Integer.MIN_VALUE - 1L);
  private static final FastHiveDecimal FASTHIVEDECIMAL_MAX_INT_VALUE_PLUS_ONE =
      new FastHiveDecimal((long) Integer.MAX_VALUE + 1L);

  private static final FastHiveDecimal FASTHIVEDECIMAL_MIN_LONG_VALUE =
      new FastHiveDecimal(Long.MIN_VALUE);
  private static final FastHiveDecimal FASTHIVEDECIMAL_MAX_LONG_VALUE =
      new FastHiveDecimal(Long.MAX_VALUE);
  private static final int MAX_LONG_DIGITS =
      FASTHIVEDECIMAL_MAX_LONG_VALUE.fastIntegerDigitCount;
  private static final FastHiveDecimal FASTHIVEDECIMAL_MIN_LONG_VALUE_MINUS_ONE =
      new FastHiveDecimal("-9223372036854775809");
  private static final FastHiveDecimal FASTHIVEDECIMAL_MAX_LONG_VALUE_PLUS_ONE =
      new FastHiveDecimal("9223372036854775808");

  private static final BigInteger BIG_INTEGER_UNSIGNED_BYTE_MAX_VALUE = BIG_INTEGER_TWO.pow(Byte.SIZE).subtract(BigInteger.ONE);
  private static final BigInteger BIG_INTEGER_UNSIGNED_SHORT_MAX_VALUE = BIG_INTEGER_TWO.pow(Short.SIZE).subtract(BigInteger.ONE);
  private static final BigInteger BIG_INTEGER_UNSIGNED_INT_MAX_VALUE = BIG_INTEGER_TWO.pow(Integer.SIZE).subtract(BigInteger.ONE);
  private static final BigInteger BIG_INTEGER_UNSIGNED_LONG_MAX_VALUE = BIG_INTEGER_TWO.pow(Long.SIZE).subtract(BigInteger.ONE);

  /**
Is the decimal value a byte? Range -128            to      127.
                                   Byte.MIN_VALUE          Byte.MAX_VALUE

Emulates testing for no value corruption:
     bigDecimalValue().setScale(0).equals(BigDecimal.valueOf(bigDecimalValue().byteValue()))

NOTE: Fractional digits are ignored in the test since fastByteValueClip() will
      remove them (round down).

@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
@return True when fastByteValueClip() will return a correct byte.
storage-api/src/java/org/apache/hadoop/hive/common/type/FastHiveDecimalImpl.java