private static long parse(byte[] bytes, int start, int length, int offset,
      int radix, boolean negative) {
    byte separator = '.';
    long max = Long.MIN_VALUE / radix;
    long result = 0, end = start + length;
    while (offset < end) {
      int digit = LazyUtils.digit(bytes[offset++], radix);
      if (digit == -1 || max > result) {
        if (bytes[offset-1] == separator) {
          // We allow decimals and will return a truncated integer in that case.
          // Therefore we won't throw an exception here (checking the fractional
          // part happens below.)
          break;
        }
        throw new NumberFormatException(LazyUtils.convertToString(bytes, start,
            length));
      }
      long next = result * radix - digit;
      if (next > result) {
        throw new NumberFormatException(LazyUtils.convertToString(bytes, start,
            length));
      }
      result = next;
    }

    // This is the case when we've encountered a decimal separator. The fractional
    // part will not change the number, but we will verify that the fractional part
    // is well formed.
    while (offset < end) {
      int digit = LazyUtils.digit(bytes[offset++], radix);
      if (digit == -1) {
        throw new NumberFormatException(LazyUtils.convertToString(bytes, start,
            length));
      }
    }

    if (!negative) {
      result = -result;
      if (result < 0) {
        throw new NumberFormatException(LazyUtils.convertToString(bytes, start,
            length));
      }
    }
    return result;
  }
/** Parses the string argument as if it was an long value and returns the
result. Throws NumberFormatException if the string does not represent an
long quantity. The second argument specifies the radix to use when parsing
the value.

@param bytes
@param start
@param length
         a UTF-8 encoded string representation of a long quantity.
@param offset
         the starting position after the sign (if exists)
@param radix
         the base to use for conversion.
@param negative
         whether the number is negative.
@return the value represented by the argument
@exception NumberFormatException
             if the argument could not be parsed as an long quantity.
serde/src/java/org/apache/hadoop/hive/serde2/lazy/LazyLong.java