CompUInt128 implements CompUInt<UInt64, UInt64, CompUInt128> { @Override public CompUInt128 add(CompUInt128 other) { long newLow = Integer.toUnsignedLong(this.low) + Integer.toUnsignedLong(other.low); long lowOverflow = newLow >>> 32; long newMid = Integer.toUnsignedLong(this.mid) + Integer.toUnsignedLong(other.mid) + lowOverflow; long midOverflow = newMid >>> 32; long newHigh = this.high + other.high + midOverflow; return new CompUInt128(newHigh, (int) newMid, (int) newLow); } CompUInt128(byte[] bytes);  CompUInt128(byte[] bytes, boolean requiresPadding);  CompUInt128(BigInteger value);   CompUInt128(long high, int mid, int low);   CompUInt128(UInt64 value);   CompUInt128(long value);   CompUInt128(CompUInt128 other); @Override CompUInt128 add(CompUInt128 other); @Override CompUInt128 multiply(CompUInt128 other); @Override CompUInt128 subtract(CompUInt128 other); @Override CompUInt128 negateUInt(); @Override boolean isZero(); @Override BigInteger toBigInteger(); @Override UInt64 getLeastSignificant(); @Override UInt64 getMostSignificant(); @Override UInt64 getLeastSignificantAsHigh(); @Override long toLong(); @Override int toInt(); @Override CompUInt128 shiftLowIntoHigh(); @Override int getLowBitLength(); @Override int getHighBitLength(); @Override String toString(); @Override byte[] toByteArray();  }
@Test public void testAdd() { assertEquals( BigInteger.ZERO, new CompUInt128(0).add(new CompUInt128(0)).toBigInteger() ); assertEquals( two, new CompUInt128(1).add(new CompUInt128(1)).toBigInteger() ); assertEquals( twoTo32, new CompUInt128(twoTo32).add(new CompUInt128(0)).toBigInteger() ); assertEquals( twoTo32.add(BigInteger.ONE), new CompUInt128(twoTo32).add(new CompUInt128(1)).toBigInteger() ); assertEquals( twoTo64, new CompUInt128(twoTo64).add(new CompUInt128(0)).toBigInteger() ); assertEquals( twoTo64.add(BigInteger.ONE), new CompUInt128(twoTo64).add(new CompUInt128(1)).toBigInteger() ); assertEquals( twoTo128.subtract(BigInteger.ONE), new CompUInt128(twoTo128.subtract(BigInteger.ONE)).add(new CompUInt128(0)) .toBigInteger() ); assertEquals( BigInteger.ZERO, new CompUInt128(twoTo128.subtract(BigInteger.ONE)) .add(new CompUInt128(BigInteger.ONE)).toBigInteger() ); assertEquals( twoTo128.subtract(new BigInteger("10000000")).add(twoTo32.add(twoTo64)).mod(twoTo128), new CompUInt128(twoTo128.subtract(new BigInteger("10000000"))) .add(new CompUInt128(twoTo32.add(twoTo64))).toBigInteger() ); assertEquals( twoTo32.add(twoTo64).mod(twoTo128), new CompUInt128(twoTo32).add(new CompUInt128(twoTo64)).toBigInteger() ); }