public static int writeLongToUTF8(byte[] result, long i) {
    if (i == 0) {
      result[0] = '0';
      return 1;
    }

    int current = 0;

    if (i < 0) {
      result[current++] ='-';
    } else {
      // negative range is bigger than positive range, so there is no risk
      // of overflow here.
      i = -i;
    }

    long start = 1000000000000000000L;
    while (i / start == 0) {
      start /= 10;
    }

    while (start > 0) {
      result[current++] = (byte) ('0' - (i / start % 10));
      start /= 10;
    }

    return current;
  }
Math expression evaluation helper functions.
Some of these are referenced from ColumnUnaryFunc.txt.
ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/MathExpr.java