@Test
  public void testCompareTo() {
    assertTrue(one.compareTo(two) < 0);
    assertTrue(two.compareTo(one) > 0);
    assertTrue(one.compareTo(zero) > 0);
    assertTrue(zero.compareTo(two) < 0);

    // compare to must compare with scaling up/down.
    Decimal128 oneScaled = new Decimal128(1L, (short) 3);
    assertTrue(one.compareTo(oneScaled) == 0);

    // exact numbers (power of 2) can do the same
    Decimal128 d1 = new Decimal128(2.0d, (short) 6);
    Decimal128 d2 = new Decimal128(2.0d, (short) 3);
    assertTrue(d1.compareTo(d2) == 0);

    // but, if the value is rounded by more scaling,
    // they will be different values.
    Decimal128 d3 = new Decimal128(2.0d / 3.0d, (short) 5);
    Decimal128 d4 = new Decimal128(2.0d / 3.0d, (short) 8);
    assertTrue(d3.compareTo(d4) != 0);

    Decimal128 d5 = new Decimal128(12, (short) 5);
    Decimal128 d6 = new Decimal128(15, (short) 7);
    assertTrue(d5.compareTo(d6) < 0);
    assertTrue(d6.compareTo(d5) > 0);

    Decimal128 d7 = new Decimal128(15, (short) 5);
    Decimal128 d8 = new Decimal128(12, (short) 7);
    assertTrue(d7.compareTo(d8) > 0);
    assertTrue(d8.compareTo(d7) < 0);
  }
This code was based on code from Microsoft's PolyBase.
common/src/test/org/apache/hadoop/hive/common/type/TestDecimal128.java