std::is_integral<
uint128_t> : std::true_type {};
27structstd::is_arithmetic<
uint128_t> : std::true_type {};
29structstd::is_unsigned<
uint128_t> : std::true_type {};
38std::string
add(
conststd::string &first,
conststd::string &second) {
40int16_t sum = 0, carry = 0;
41 for(int32_t i =
static_cast<int32_t
>(first.size()) - 1,
42j =
static_cast<int32_t
>(second.size()) - 1;
43i >= 0 || j >= 0; --i, --j) {
44sum = ((i >= 0 ? first[i] -
'0': 0) + (j >= 0 ? second[j] -
'0': 0) +
48third.push_back(sum +
'0');
51third.push_back(
'1');
53std::reverse(third.begin(), third.end());
71this->f = this->s = 0;
72 if(str.size() > 1 && str[1] ==
'x') {
73 for(
autoi = 2; i < str.size(); ++i) {
75 if(str[i] >=
'0'&& str[i] <=
'9') {
76*
this+= (str[i] -
'0');
77}
else if(str[i] >=
'A'&& str[i] <=
'F') {
78*
this+= (str[i] -
'A'+ 10);
79}
else if(str[i] >=
'a'&& str[i] <=
'f') {
80*
this+= (str[i] -
'a'+ 10);
84 for(
auto&x : str) {
99 template<
typenameT,
typename=
typenamestd::enable_if<
100std::is_integral<T>::value, T>::type>
116 uint128_t(
constuint64_t high,
constuint64_t low) : f(high), s(low) {}
128 uint128_t(uint128_t &&num) noexcept : f(num.f), s(num.s) {}
143 return__builtin_clzll(f);
145 return64 + __builtin_clzll(s);
148_BitScanForward64(&r, f);
151_BitScanForward64(&l, s);
166 return__builtin_ctzll(f);
168 return64 + __builtin_ctzll(s);
171_BitScanReverse64(&r, s);
174_BitScanReverse64(&l, f);
185 inline explicit operatorbool()
const{
return(f || s); }
192 template<
typenameT,
typename=
typenamestd::enable_if<
193std::is_integral<T>::value, T>::type>
194 inline explicit operatorT()
const{
195 return static_cast<T
>(s);
202 inlineuint64_t
lower()
const{
returns; }
208 inlineuint64_t
upper()
const{
returnf; }
216 template<
typenameT,
typename=
typenamestd::enable_if<
217std::is_integral<T>::value, T>::type>
238 inlineuint128_t &
operator=(
constuint128_t &p) =
default;
243 inlineuint128_t &
operator=(uint128_t &&p) =
default;
251 template<
typenameT,
typename=
typenamestd::enable_if<
252std::is_integral<T>::value, T>::type>
254 returnuint128_t(f + (p + s < s), p + s);
263 returnuint128_t(f + (p.s + s < s) + p.f, p.s + s);
272 template<
typenameT,
typename=
typenamestd::enable_if<
273std::is_integral<T>::value, T>::type>
275 boolapp = p + s < s;
287 boolapp = p.s + s < s;
317 template<
typenameT,
typename=
typenamestd::enable_if<
318std::is_integral<T>::value, T>::type>
321 returnuint128_t(f - app, s - p);
331 returnuint128_t(f - p.f - app, s - p.s);
338 inlineuint128_t
operator-() {
return~*
this+ uint128_t(1); }
364 template<
typenameT,
typename=
typenamestd::enable_if<
365std::is_integral<T>::value, T>::type>
391 template<
typenameT,
typename=
typenamestd::enable_if<
392std::is_integral<T>::value, T>::type>
394 return*
this* uint128_t(p);
403uint64_t f_first = s >> 32, f_second = s & 0xFFFFFFFF,
404s_first = p.s >> 32, s_second = p.s & 0xFFFFFFFF;
405uint64_t fi = f_first * s_first, se = f_first * s_second,
406th = s_first * f_second, fo = s_second * f_second;
407uint64_t tmp = ((se & 0xFFFFFFFF) << 32), tmp2 = (th & 0xFFFFFFFF)
409 intcc = (tmp + tmp2 < tmp);
411cc += (tmp + fo < tmp);
412uint64_t carry = fi + (se >> 32) + (th >> 32);
413 returnuint128_t(this->f * p.s + this->s * p.f + carry + cc, tmp + fo);
422 template<
typenameT,
typename=
typenamestd::enable_if<
423std::is_integral<T>::value, T>::type>
425*
this*= uint128_t(p);
435uint64_t f_first = s >> 32, f_second = s & 0xFFFFFFFF,
436s_first = p.s >> 32, s_second = p.s & 0xFFFFFFFF;
437uint64_t fi = f_first * s_first, se = f_first * s_second,
438th = s_first * f_second, fo = s_second * f_second;
439uint64_t tmp = (se << 32), tmp2 = (th << 32);
440 intcc = (tmp + tmp2 < tmp);
442cc += (tmp + fo < tmp);
443uint64_t carry = fi + (se >> 32) + (th >> 32);
444f = this->f * p.s + this->s * p.f + carry + cc;
455std::pair<uint128_t, uint128_t>
divide(
constuint128_t &p) {
457 return{uint128_t(0), *
this};
458}
else if(*
this== p) {
459 return{uint128_t(1), uint128_t(0)};
461uint128_t tmp = p, tmp2 = *
this;
462uint16_t left = tmp.
_lez() -
_lez();
464uint128_t quotient(0);
467uint16_t shf = tmp2._lez() - tmp.
_lez();
481 return{quotient << left, tmp2};
497 template<
typenameT,
typename=
typenamestd::enable_if<
498std::is_integral<T>::value, T>::type>
500uint128_t tmp = *
this;
501tmp /= uint128_t(0, p);
511*
this=
divide(p).first;
521 template<
typenameT,
typename=
typenamestd::enable_if<
522std::is_integral<T>::value, T>::type>
524*
this/= uint128_t(0, p);
541 template<
typenameT,
typename=
typenamestd::enable_if<
542std::is_integral<T>::value, T>::type>
544 return*
this% uint128_t(p);
553*
this=
divide(p).second;
563 template<
typenameT,
typename=
typenamestd::enable_if<
564std::is_integral<T>::value, T>::type>
566*
this%= uint128_t(p);
576 returnf < other.f || (f == other.f && s < other.s);
585 returnf < other.f || (f == other.f && s <= other.s);
594 returnf > other.f || (f == other.f && s > other.s);
603 return(f > other.f) || (f == other.f && s >= other.s);
612 returnf == other.f && s == other.s;
621 returnf != other.f || s != other.s;
636 return(s || f) && (b.s || b.f);
645 return(s || f) || (b.s || b.f);
660 template<
typenameT,
typename=
typenamestd::enable_if<
661std::is_integral<T>::value, T>::type>
663 return*
this< uint128_t(other);
672 template<
typenameT,
typename=
typenamestd::enable_if<
673std::is_integral<T>::value, T>::type>
675 return*
this<= uint128_t(other);
684 template<
typenameT,
typename=
typenamestd::enable_if<
685std::is_integral<T>::value, T>::type>
687 return*
this> uint128_t(other);
696 template<
typenameT,
typename=
typenamestd::enable_if<
697std::is_integral<T>::value, T>::type>
699 return*
this>= uint128_t(other);
708 template<
typenameT,
typename=
typenamestd::enable_if<
709std::is_integral<T>::value, T>::type>
711 return*
this== uint128_t(other);
720 template<
typenameT,
typename=
typenamestd::enable_if<
721std::is_integral<T>::value, T>::type>
723 return*
this!= uint128_t(other);
732 template<
typenameT,
typename=
typenamestd::enable_if<
733std::is_integral<T>::value, T>::type>
735 return(f || s) && b;
745 template<
typenameT,
typename=
typenamestd::enable_if<
746std::is_integral<T>::value, T>::type>
748 return(f || s) || b;
755uint128_t
operator~() {
returnuint128_t(~this->f, ~this->s); }
763 template<
typenameT,
typename=
typenamestd::enable_if<
764std::is_integral<T>::value, T>::type>
767 returnuint128_t(f, s);
768}
else if(p >= 64 && p <= 128) {
769 returnuint128_t((this->s << (p - 64)), 0);
770}
else if(p < 64 && p > 0) {
771 returnuint128_t((this->f << p) + ((this->s >> (64 - p))),
783 template<
typenameT,
typename=
typenamestd::enable_if<
784std::is_integral<T>::value, T>::type>
787 if(p >= 64 && p <= 128) {
788this->f = (this->s << (p - 64));
791f = ((this->f << p) + (this->s >> (64 - p)));
804 template<
typenameT,
typename=
typenamestd::enable_if<
805std::is_integral<T>::value, T>::type>
808 returnuint128_t(this->f, this->s);
809}
else if(p >= 64 && p <= 128) {
810 returnuint128_t(0, (this->f >> (p - 64)));
811}
else if(p < 64 && p > 0) {
812 returnuint128_t((this->f >> p),
813(this->s >> p) + (this->f << (64 - p)));
824 template<
typenameT,
typename=
typenamestd::enable_if<
825std::is_integral<T>::value, T>::type>
830s = (this->f >> (p - 64));
832s = (this->s >> p) + (this->f << (64 - p));
845 returnuint128_t(this->f & p.f, this->s & p.s);
854 template<
typenameT,
typename=
typenamestd::enable_if<
855std::is_integral<T>::value, T>::type>
857uint128_t tmp = *
this;
858 returntmp & uint128_t(p);
878 template<
typenameT,
typename=
typenamestd::enable_if<
879std::is_integral<T>::value, T>::type>
881*
this&= uint128_t(p);
891 template<
typenameT,
typename=
typenamestd::enable_if<
892std::is_integral<T>::value, T>::type>
894 returnuint128_t(p | s);
903 returnuint128_t(this->f | p.f, this->s | p.s);
923 template<
typenameT,
typename=
typenamestd::enable_if<
924std::is_integral<T>::value, T>::type>
936 template<
typenameT,
typename=
typenamestd::enable_if<
937std::is_integral<T>::value, T>::type>
939 returnuint128_t(this->f, this->s ^ p);
948 returnuint128_t(this->f ^ p.f, this->s ^ p.s);
968 template<
typenameT,
typename=
typenamestd::enable_if<
969std::is_integral<T>::value, T>::type>
984 friendstd::ostream &
operator<<(std::ostream &op,
constuint128_t &p) {
988std::string out =
"0", p_2 =
"1";
989 for(
inti = 0; i < 64; ++i) {
990 if(p.s & (1LL << i)) {
991out =
add(out, p_2);
993p_2 =
add(p_2, p_2);
995 for(
inti = 0; i < 64; ++i) {
996 if(p.f & (1LL << i)) {
997out =
add(out, p_2);
999p_2 =
add(p_2, p_2);
1008template<
typenameT,
typename=
typenamestd::enable_if<
1009std::is_integral<T>::value, T>::type>
1014template<
typenameT,
typename=
typenamestd::enable_if<
1015std::is_integral<T>::value, T>::type>
1020template<
typenameT,
typename=
typenamestd::enable_if<
1021std::is_integral<T>::value, T>::type>
1026template<
typenameT,
typename=
typenamestd::enable_if<
1027std::is_integral<T>::value, T>::type>
1032template<
typenameT,
typename=
typenamestd::enable_if<
1033std::is_integral<T>::value, T>::type>
1039template<
typenameT,
typename=
typenamestd::enable_if<
1040std::is_integral<T>::value, T>::type>
1045template<
typenameT,
typename=
typenamestd::enable_if<
1046std::is_integral<T>::value, T>::type>
1051template<
typenameT,
typename=
typenamestd::enable_if<
1052std::is_integral<T>::value, T>::type>
1058template<
typenameT,
typename=
typenamestd::enable_if<
1059std::is_integral<T>::value, T>::type>
1060inline booloperator&&(
constT p,
const uint128_t&q) {
1064template<
typenameT,
typename=
typenamestd::enable_if<
1065std::is_integral<T>::value, T>::type>
1066inline booloperator||(
constT p,
const uint128_t&q) {
1071template<
typenameT,
typename=
typenamestd::enable_if<
1072std::is_integral<T>::value, T>::type>
1073inline booloperator==(
constT p,
const uint128_t&q) {
1077template<
typenameT,
typename=
typenamestd::enable_if<
1078std::is_integral<T>::value, T>::type>
1079inline booloperator!=(
constT p,
const uint128_t&q) {
1083template<
typenameT,
typename=
typenamestd::enable_if<
1084std::is_integral<T>::value, T>::type>
1085inline booloperator<(
constT p,
const uint128_t&q) {
1089template<
typenameT,
typename=
typenamestd::enable_if<
1090std::is_integral<T>::value, T>::type>
1091inline booloperator<=(
constT p,
const uint128_t&q) {
1095template<
typenameT,
typename=
typenamestd::enable_if<
1096std::is_integral<T>::value, T>::type>
1097inline booloperator>(
constT p,
const uint128_t&q) {
1101template<
typenameT,
typename=
typenamestd::enable_if<
1102std::is_integral<T>::value, T>::type>
1103inline booloperator>=(
constT p,
const uint128_t&q) {
class for 128-bit unsigned integer
uint128_t & operator%=(const T &p)
operator %= for uint128_t
uint128_t operator-()
operator - using twos complement
uint128_t & operator-=(const T &p)
operator -= for uint128_t and other integer types.
bool operator&&(const T b)
operator && for other types
uint128_t & operator>>=(const T p)
operator >>= for uint128_t
uint128_t(const std::string &str)
Parameterized constructor.
uint128_t operator+(const uint128_t &p)
operator + for uint128_t and other integer types.
uint128_t operator<<(const T p)
operator << for uint128_t
bool operator<=(const uint128_t &other)
operator <= for uint128_t
uint128_t & operator--()
operator – (pre-decrement)
uint64_t upper() const
returns upper 64-bit integer part
uint128_t & operator&=(const T p)
operator &= for other types (bitwise operator)
uint128_t & operator%=(const uint128_t &p)
operator %= for uint128_t
bool operator>(const uint128_t &other)
operator > for uint128_t
uint128_t operator--(int p)
operator – (post-decrement)
uint128_t operator|(const uint128_t &p)
operator | for uint128_t (bitwise operator)
uint128_t & operator/=(const uint128_t &p)
operator /= for uint128_t
uint128_t & operator*=(const T p)
operator *= for uint128_t and other integer types.
uint128_t operator/(const uint128_t &p)
operator / for uint128_t and other integer types.
bool operator||(const uint128_t &b)
operator || for uint128_t
bool operator>=(const T other)
operator >= for other types
uint128_t & operator=(uint128_t &&p)=default
Move assignment operator.
uint128_t operator|(const T p)
operator | for other types (bitwise operator)
~uint128_t()=default
Destructor for uint128_t.
uint128_t operator~()
operator ~ for uint128_t
uint128_t operator*(const uint128_t &p)
operator * for uint128_t and other integer types.
uint128_t & operator^=(const T &p)
operator ^= for other types (bitwise operator)
bool operator<=(const T other)
operator <= for other types
uint128_t operator*(const T p)
operator * for uint128_t and other integer types.
uint128_t operator+(const T p)
operator + for uint128_t and other integer types.
uint128_t & operator+=(const T p)
operator += for uint128_t and other integer types.
bool operator<(const T other)
operator < for other types
friend std::ostream & operator<<(std::ostream &op, const uint128_t &p)
operator << for printing uint128_t integer
uint128_t(const uint128_t &num)=default
Copy constructor.
uint128_t & operator|=(const T p)
operator |= for other types (bitwise operator)
uint128_t operator-(const T &p)
operator - for uint128_t and other integer types.
uint128_t operator>>(const T p)
operator >> for uint128_t
bool operator!=(const T other)
operator != for other types
bool operator==(const T other)
operator == for other types
bool operator==(const uint128_t &other)
operator == for uint128_t
uint32_t _trz()
Trailing zeroes in binary.
uint128_t(uint128_t &&num) noexcept
Move constructor.
bool operator||(const T b)
operator || for other types
uint128_t operator-(const uint128_t &p)
operator - for uint128_t
bool operator>(const T other)
operator > for other types
void __get_integer_from_string(const std::string &str)
First and second half of 128 bit number.
std::pair< uint128_t, uint128_t > divide(const uint128_t &p)
divide function for uint128_t and other integer types.
uint128_t operator^(const uint128_t &p)
operator ^ for uint128_t (bitwise operator)
uint128_t(const uint64_t high, const uint64_t low)
Parameterized constructor.
uint128_t & operator*=(const uint128_t &p)
operator *= for uint128_t and other integer types.
uint128_t & operator+=(const uint128_t &p)
operator += for uint128_t
uint128_t operator&(const T p)
operator & for other types (bitwise operator)
uint128_t & operator<<=(const T p)
operator <<= for uint128_t
uint64_t lower() const
returns lower 64-bit integer part
uint128_t & operator/=(const T p)
operator /= for uint128_t and other integer types.
uint128_t operator^(const T p)
operator ^ for other types (bitwise operator)
bool operator&&(const uint128_t &b)
operator && for uint128_t
bool operator!=(const uint128_t &other)
operator != for uint128_t
uint128_t & operator=(const uint128_t &p)=default
operator = for uint128_t
uint128_t & operator|=(const uint128_t &p)
operator |= for uint128_t (bitwise operator)
uint128_t & operator=(const std::string &p)
operator = for type string
uint128_t & operator-=(const uint128_t &p)
operator -= for uint128_t
uint128_t operator%(const uint128_t &p)
operator % for uint128_t
uint128_t & operator&=(const uint128_t &p)
operator &= for uint128_t (bitwise operator)
uint128_t & operator++()
pre-increment operator
uint128_t & operator=(const T &p)
operator = for other types
bool operator<(const uint128_t &other)
operator < for uint128_t
uint128_t operator&(const uint128_t &p)
operator & for uint128_t (bitwise operator)
bool operator!()
operator ! for uint128_t
uint128_t(T low)
Parameterized constructor.
uint128_t operator%(const T &p)
operator % for uint128_t and other integer types.
uint128_t & operator^=(const uint128_t &p)
operator ^= for uint128_t (bitwise operator)
bool operator>=(const uint128_t &other)
operator >= for uint128_t
uint128_t operator/(const T p)
operator / for uint128_t and other integer types.
uint32_t _lez()
Leading zeroes in binary.
bool operator()()
operator () for uint128_t
uint128_t operator++(int)
post-increment operator
std::string add(const std::string &first, const std::string &second)
Adding two string.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4