The OpenD Programming Language

extendedMul

  1. UInt!(sizeA + sizeB) extendedMul(UInt!sizeA a, UInt!sizeB b)
  2. UInt!(size + size_t.sizeof * 8) extendedMul(UInt!size a, size_t b)
    @safe pure nothrow @nogc
    UInt!(size + size_t.sizeof * 8)
    extendedMul
    (
    size_t size
    )
    (
    UInt!size a
    ,
    size_t b
    )
  3. auto extendedMul(ulong a, ulong b)
  4. auto extendedMul(uint a, uint b)

Examples

auto a = UInt!128.max;
auto b = UInt!256.max;
auto c = UInt!384.max;
assert(extendedMul(a, a) == UInt!256.max - UInt!128.max - UInt!128.max);
assert(extendedMul(a, b) == UInt!384.max - UInt!128.max - UInt!256.max);
assert(extendedMul(b, a) == UInt!384.max - UInt!128.max - UInt!256.max);

a = UInt!128.fromHexString("dfbbfae3cd0aff2714a1de7022b0029d");
b = UInt!256.fromHexString("3fe48f2dc8aad570d037bc9b323fc0cfa312fcc2f63cb521bd8a4ca6157ef619");
c = UInt!384.fromHexString("37d7034b86e8d58a9fc564463fcedef9e2ad1126dd2c0f803e61c72852a9917ef74fa749e7936a9e4e224aeeaff91f55");
assert(extendedMul(a, b) == c);
assert(extendedMul(b, a) == c);

a = UInt!128.fromHexString("23edf5ff44ee3a4feafc652607aa1eb9");
b = UInt!256.fromHexString("d3d79144b8941fb50c9102e3251bacb112c88b71ad3f85a970a31458ce24297b");
c = UInt!384.fromHexString("1dbb62fe6ca5fed101068eda7222d6a9857633ecdfed37a2d156ff6309065ecc633f31465727677a93a7acbd1dac63e3");
assert(extendedMul(a, b) == c);
assert(extendedMul(b, a) == c);

ulong

ulong a = 0xdfbbfae3cd0aff27;
ulong b = 0x14a1de7022b0029d;
auto c = UInt!128.fromHexString("120827399968ea2a2db185d16e8cc8eb");
assert(extendedMul(a, b) == c);
assert(extendedMul(b, a) == c);

uint

uint a = 0xdfbbfae3;
uint b = 0xcd0aff27;
auto c = UInt!64.fromHexString("b333243de8695595");
assert(extendedMul(a, b) == c);
assert(extendedMul(b, a) == c);

Meta