@Test
  public void testDivide() {
    Decimal128 quotient = new Decimal128();
    Decimal128.divide(two, one, quotient, (short) 2);
    assertEquals(0, quotient.compareTo(two));

    Decimal128.divide(two, two, quotient, (short) 2);
    assertEquals(0, quotient.compareTo(one));

    Decimal128 three = new Decimal128(3);
    Decimal128 four = new Decimal128(4);
    Decimal128.divide(three, four, quotient, (short) 2);
    assertEquals("0.75", quotient.toFormalString());

    Decimal128.divide(three, four, quotient, (short) 1);
    assertEquals("0.8", quotient.toFormalString());

    Decimal128.divide(three, four, quotient, (short) 0);
    assertEquals("1", quotient.toFormalString());

    Decimal128 two = new Decimal128(2);
    Decimal128.divide(two, three, quotient, (short) 4);
    assertEquals("0.6667", quotient.toFormalString());
  }
This code was based on code from Microsoft's PolyBase.
common/src/test/org/apache/hadoop/hive/common/type/TestDecimal128.java