// Number of random products to test. privatestaticfinalint COUNT = 1 << 16;
// Initialize shared random number generator privatestatic java.util.Random rnd = RandomFactory.getRandom();
// Calculate high 64 bits of 128 product using BigInteger. privatestaticlong multiplyHighBigInt(long x, long y) { return BigInteger.valueOf(x).multiply(BigInteger.valueOf(y))
.shiftRight(64).longValue();
}
// Calculate high 64 bits of unsigned 128 product using signed multiply privatestaticlong unsignedMultiplyHigh(long x, long y) { long x0 = x & 0xffffffffL; long x1 = x >>> 32; long y0 = y & 0xffffffffL; long y1 = y >>> 32;
long t = x1 * y0 + ((x0 * y0) >>> 32); long z0 = x0 * y1 + (t & 0xffffffffL); long z1 = t >>> 32;
return x1 * y1 + z1 + (z0 >>> 32);
}
// Compare results of two functions for a pair of values privatestaticboolean check(BiFunction<Long,Long,Long> reference,
BiFunction<Long,Long,Long> multiply, long x, long y) { long p1 = reference.apply(x, y); long p2 = multiply.apply(x, y); if (p1 != p2) {
System.err.printf("Error - x:%d y:%d p1:%d p2:%d\n", x, y, p1, p2); returnfalse;
} else { returntrue;
}
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.