16 uint128_t top[4] = { value1.
upper().upper(), value1.upper().lower(), value1.lower().upper(), value1.lower().lower() };
17 uint128_t bottom[4] = { value2.
upper().upper(), value2.upper().lower(), value2.lower().upper(), value2.lower().lower() };
21 for (
int y = 3; y > -1; --y)
22 for (
int x = 3; x > -1; --x)
23 products[3 - x][y] = top[x] * bottom[y];
32 third64 +=
uint128_t(products[1][3].lower());
37 second64 +=
uint128_t(products[2][3].lower());
41 first64 +=
uint128_t(products[3][3].lower());
51 if (((
bool)value2._upper) || (shift >= 256))
53 else if (shift == 128)
58 return uint256_t((value1._upper << shift) + (value1._lower >> (128 - shift)), value1._lower << shift);
59 else if ((256 > shift) && (shift > 128))
60 return uint256_t(value1._lower << (shift - 128), 0);
69 if (((
bool)value2._upper) || (shift >= 256))
71 else if (shift == 128)
76 return uint256_t(value1._upper >> shift, (value1._upper << (128 - shift)) + (value1._lower >> shift));
77 else if ((256 > shift) && (shift > 128))
78 return uint256_t(value1._upper >> (shift - 128));
112 if ((base < 2) || (base > 16))
113 throw std::invalid_argument(
"Base must be in the range [2, 16]");
121 std::pair<uint256_t, uint256_t> qr(*
this, 0);
125 out =
"0123456789abcdef"[(uint8_t)qr.second] + out;
126 }
while (qr.first != 0);
129 if (out.size() < length)
130 out = std::string(length - out.size(),
'0') + out;
137 if ((base < 2) || (base > 16))
138 throw std::invalid_argument(
"Base must be in the range [2, 16]");
146 std::pair<uint256_t, uint256_t> qr(*
this, 0);
150 out = L
"0123456789abcdef"[(uint8_t)qr.second] + out;
151 }
while (qr.first != 0);
154 if (out.size() < length)
155 out = std::wstring(length - out.size(), L
'0') + out;
163 throw std::domain_error(
"Division by 0");
165 return std::pair<uint256_t, uint256_t>(x, 0);
167 return std::pair<uint256_t, uint256_t>(1, 0);
168 else if ((x == 0) || (x < y))
169 return std::pair<uint256_t, uint256_t>(0, x);
171 std::pair<uint256_t, uint256_t> result(0, x);
176 if (copyd > result.second)
182 while (result.second >= y)
184 if (result.second >= copyd)
186 result.second -= copyd;
187 result.first |= adder;
Unsigned 128-bit integer type.
uint64_t upper() const noexcept
Get the upper part of the 128-bit integer.
Unsigned 256-bit integer type.
size_t bits() const noexcept
Get the count of bits.
uint128_t lower() const noexcept
Get the lower part of the 256-bit integer.
uint128_t upper() const noexcept
Get the upper part of the 256-bit integer.
std::wstring wstring(size_t base=10, size_t length=0) const
Get wide string from the current 128-bit integer.
std::string string(size_t base=10, size_t length=0) const
Get string from the current 128-bit integer.
static std::pair< uint256_t, uint256_t > divmod(const uint256_t &x, const uint256_t &y)
Calculate quotient and remainder when dividing X by Y.
C++ Common project definitions.
std::ostream & operator<<(std::ostream &os, const uint128_t &value)
uint128_t operator*(const uint128_t &value1, const uint128_t &value2) noexcept
uint128_t operator>>(const uint128_t &value1, const uint128_t &value2) noexcept
Unsigned 256-bit integer type definition.