9 #ifndef CPPCOMMON_UINT128_H
10 #define CPPCOMMON_UINT128_H
18 #include <type_traits>
40 explicit uint128_t(
const T& value) noexcept;
41 template <
typename TUpper,
typename TLower>
48 uint128_t& operator=(const T& value) noexcept;
53 uint128_t operator+() const noexcept {
return *
this; }
101 template <
typename T>
103 template <
typename T>
107 template <
typename T>
109 template <
typename T>
113 template <
typename T>
115 template <
typename T>
126 template <
typename T>
128 template <
typename T>
130 template <
typename T>
133 template <
typename T>
135 template <
typename T>
137 template <
typename T>
140 template <
typename T>
142 template <
typename T>
146 template <
typename T>
148 template <
typename T>
152 template <
typename T>
154 template <
typename T>
159 template <
typename T>
161 template <
typename T>
165 template <
typename T>
167 template <
typename T>
171 template <
typename T>
173 template <
typename T>
177 template <
typename T>
179 template <
typename T>
183 template <
typename T>
185 template <
typename T>
189 template <
typename T>
191 template <
typename T>
196 bool operator!() const noexcept {
return !(bool)(_upper | _lower); }
198 template <
typename T>
200 template <
typename T>
204 template <
typename T>
206 template <
typename T>
214 template <
typename T>
216 template <
typename T>
219 template <
typename T>
221 template <
typename T>
224 template <
typename T>
237 template <
typename T>
251 operator bool() const noexcept {
return (
bool)(_upper | _lower); }
252 operator uint8_t() const noexcept {
return (uint8_t)_lower; }
253 operator uint16_t() const noexcept {
return (uint16_t)_lower; }
254 operator uint32_t() const noexcept {
return (uint32_t)_lower; }
255 operator uint64_t() const noexcept {
return (uint64_t)_lower; }
258 uint64_t
upper() const noexcept {
return _upper; }
260 uint64_t
lower() const noexcept {
return _lower; }
263 size_t bits() const noexcept;
271 std::
string string(
size_t base = 10,
size_t length = 0) const;
289 friend std::istream& operator>>(std::istream& is,
uint128_t& value)
290 { is >> value._upper >> value._lower;
return is; }
293 { is >> value._upper >> value._lower;
return is; }
Unsigned 128-bit integer type.
uint128_t & operator>>=(const T &value) noexcept
static std::pair< uint128_t, uint128_t > divmod(const uint128_t &x, const uint128_t &y)
Calculate quotient and remainder when dividing X by Y.
friend uint128_t operator>>(int8_t value1, const uint128_t &value2) noexcept
uint128_t & operator%=(const uint128_t &value)
void swap(uint128_t &value) noexcept
Swap two instances.
friend bool operator>(const T &value1, const uint128_t &value2) noexcept
uint128_t & operator>>=(const uint128_t &value) noexcept
friend uint128_t operator>>(uint8_t value1, const uint128_t &value2) noexcept
friend uint128_t operator-(const uint128_t &value1, const T &value2) noexcept
friend uint128_t operator/(const uint128_t &value1, const T &value2)
friend T & operator<<=(T &value1, const uint128_t &value2) noexcept
friend uint128_t operator>>(int16_t value1, const uint128_t &value2) noexcept
uint128_t & operator+=(const T &value) noexcept
friend uint128_t operator&(const uint128_t &value1, const T &value2) noexcept
uint128_t & operator<<=(const T &value) noexcept
friend uint128_t operator*(const T &value1, const uint128_t &value2) noexcept
friend uint128_t operator>>(int32_t value1, const uint128_t &value2) noexcept
friend uint128_t operator<<(bool value1, const uint128_t &value2) noexcept
friend bool operator<(const T &value1, const uint128_t &value2) noexcept
uint128_t & operator-=(const T &value) noexcept
uint128_t & operator&=(const uint128_t &value) noexcept
friend bool operator||(const uint128_t &value1, const T &value2) noexcept
uint128_t & operator^=(const T &value) noexcept
uint128_t operator~() const noexcept
friend uint128_t operator<<(int32_t value1, const uint128_t &value2) noexcept
uint128_t(uint128_t &&value) noexcept=default
uint128_t & operator++() noexcept
friend uint128_t operator>>(int64_t value1, const uint128_t &value2) noexcept
friend uint128_t operator+(const T &value1, const uint128_t &value2) noexcept
friend bool operator>(const uint128_t &value1, const T &value2) noexcept
uint128_t(const uint128_t &value) noexcept=default
friend uint128_t operator/(const T &value1, const uint128_t &value2)
friend bool operator<=(const uint128_t &value1, const T &value2) noexcept
uint128_t & operator^=(const uint128_t &value) noexcept
friend bool operator<=(const T &value1, const uint128_t &value2) noexcept
uint128_t operator--(int) noexcept
friend T & operator*=(T &value1, const uint128_t &value2) noexcept
friend bool operator!=(const T &value1, const uint128_t &value2) noexcept
uint128_t & operator*=(const T &value) noexcept
uint128_t operator++(int) noexcept
uint128_t & operator+=(const uint128_t &value) noexcept
uint128_t & operator|=(const uint128_t &value) noexcept
friend uint128_t operator%(const T &value1, const uint128_t &value2)
friend bool operator>=(const T &value1, const uint128_t &value2) noexcept
uint128_t operator-() const noexcept
friend bool operator==(const uint128_t &value1, const T &value2) noexcept
size_t bits() const noexcept
Get the count of bits.
friend T & operator&=(T &value1, const uint128_t &value2) noexcept
friend uint128_t operator^(const uint128_t &value1, const T &value2) noexcept
friend uint128_t operator-(const T &value1, const uint128_t &value2) noexcept
friend T & operator-=(T &value1, const uint128_t &value2) noexcept
friend uint128_t operator>>(bool value1, const uint128_t &value2) noexcept
friend uint128_t operator<<(uint64_t value1, const uint128_t &value2) noexcept
uint128_t operator+() const noexcept
friend uint128_t operator>>(const uint128_t &value1, const T &value2) noexcept
uint128_t & operator|=(const T &value) noexcept
uint128_t & operator*=(const uint128_t &value) noexcept
uint128_t & operator/=(const uint128_t &value)
uint128_t & operator%=(const T &value)
friend uint128_t operator<<(int16_t value1, const uint128_t &value2) noexcept
uint128_t & operator&=(const T &value) noexcept
friend uint128_t operator|(const uint128_t &value1, const T &value2) noexcept
friend uint128_t operator*(const uint128_t &value1, const T &value2) noexcept
std::wstring wstring(size_t base=10, size_t length=0) const
Get wide string from the current 128-bit integer.
friend bool operator&&(const T &value1, const uint128_t &value2) noexcept
friend T & operator+=(T &value1, const uint128_t &value2) noexcept
friend bool operator==(const T &value1, const uint128_t &value2) noexcept
~uint128_t() noexcept=default
friend uint128_t operator&(const T &value1, const uint128_t &value2) noexcept
friend std::wistream & operator>>(std::wistream &is, uint128_t &value)
Input instance from the given wide input stream.
uint64_t lower() const noexcept
Get the lower part of the 128-bit integer.
friend uint128_t operator<<(uint8_t value1, const uint128_t &value2) noexcept
friend uint128_t operator^(const T &value1, const uint128_t &value2) noexcept
uint128_t & operator--() noexcept
friend bool operator||(const T &value1, const uint128_t &value2) noexcept
friend T & operator|=(T &value1, const uint128_t &value2) noexcept
friend uint128_t operator+(const uint128_t &value1, const T &value2) noexcept
friend bool operator!=(const uint128_t &value1, const T &value2) noexcept
friend T & operator^=(T &value1, const uint128_t &value2) noexcept
friend uint128_t operator<<(int8_t value1, const uint128_t &value2) noexcept
friend uint128_t operator>>(uint64_t value1, const uint128_t &value2) noexcept
friend T & operator>>=(T &value1, const uint128_t &value2) noexcept
uint128_t & operator/=(const T &value)
friend uint128_t operator%(const uint128_t &value1, const T &value2)
friend uint128_t operator>>(uint16_t value1, const uint128_t &value2) noexcept
bool operator!() const noexcept
friend uint128_t operator>>(uint32_t value1, const uint128_t &value2) noexcept
uint64_t upper() const noexcept
Get the upper part of the 128-bit integer.
friend uint128_t operator<<(uint16_t value1, const uint128_t &value2) noexcept
uint128_t & operator<<=(const uint128_t &value) noexcept
friend T & operator/=(T &value1, const uint128_t &value2)
friend uint128_t operator<<(const uint128_t &value1, const T &value2) noexcept
friend bool operator<(const uint128_t &value1, const T &value2) noexcept
friend bool operator>=(const uint128_t &value1, const T &value2) noexcept
friend uint128_t operator<<(uint32_t value1, const uint128_t &value2) noexcept
friend uint128_t operator|(const T &value1, const uint128_t &value2) noexcept
friend T & operator%=(T &value1, const uint128_t &value2)
uint128_t & operator-=(const uint128_t &value) noexcept
friend uint128_t operator<<(int64_t value1, const uint128_t &value2) noexcept
friend bool operator&&(const uint128_t &value1, const T &value2) noexcept
C++ Common project definitions.
Unsigned 128-bit integer type inline implementation.