@Override
  public int compareTo(Decimal128 val) {
    if (val == this) {
      return 0;
    }

    if (this.signum != val.signum) {
      return this.signum - val.signum;
    }

    int cmp;
    if (this.scale >= val.scale) {
      cmp = this.unscaledValue.compareToScaleTen(val.unscaledValue,
          (short) (this.scale - val.scale));
    } else {
      cmp = - val.unscaledValue.compareToScaleTen(this.unscaledValue,
          (short) (val.scale - this.scale));
    }
    return cmp * this.signum;
  }
Compares this {@code Decimal128} with the specified {@code Decimal128}. Two
{@code Decimal128} objects that are equal in value but have a different
scale (like 2.0 and 2.00) are considered equal by this method. This method
is provided in preference to individual methods for each of the six boolean
comparison operators ({@literal <}, ==, {@literal >}, {@literal >=}, !=,
{@literal <=}). The suggested idiom for performing these comparisons is:
{@code (x.compareTo(y)} &lt;<i>op</i>&gt; {@code 0)}, where
&lt;<i>op</i>&gt; is one of the six comparison operators.

@param val
         {@code Decimal128} to which this {@code Decimal128} is to be
         compared.
@return a negative integer, zero, or a positive integer as this
        {@code Decimal128} is numerically less than, equal to, or greater
        than {@code val}.
common/src/java/org/apache/hadoop/hive/common/type/Decimal128.java