private long unsignedLongDiv(long x, int m) {
    if (x >= 0) {
      return x / m;
    }

    // Let uval be the value of the unsigned long with the same bits as x
    // Two's complement => x = uval - 2*MAX - 2
    // => uval = x + 2*MAX + 2
    // Now, use the fact: (a+b)/c = a/c + b/c + (a%c+b%c)/c
    return x / m + 2 * (Long.MAX_VALUE / m) + 2 / m
        + (x % m + 2 * (Long.MAX_VALUE % m) + 2 % m) / m;
  }
Divide x by m as if x is an unsigned 64-bit integer. Examples:
unsignedLongDiv(-1, 2) == Long.MAX_VALUE unsignedLongDiv(6, 3) == 2
unsignedLongDiv(0, 5) == 0

@param x
         is treated as unsigned
@param m
         is treated as signed
ql/src/java/org/apache/hadoop/hive/ql/udf/UDFConv.java