std::is_integral<
uint256_t> : std::true_type {};
24structstd::is_arithmetic<
uint256_t> : std::true_type {};
27structstd::is_unsigned<
uint256_t> : std::true_type {};
45 if(str.size() > 1 && str[1] ==
'x') {
46 for(
autoi = 2; i < str.size(); ++i) {
48 if(str[i] >=
'0'&& str[i] <=
'9') {
49*
this+= (str[i] -
'0');
50}
else if(str[i] >=
'A'&& str[i] <=
'F') {
51*
this+= (str[i] -
'A'+ 10);
52}
else if(str[i] >=
'a'&& str[i] <=
'f') {
53*
this+= (str[i] -
'a'+ 10);
57 for(
auto&x : str) {
73 template<
typenameT,
typename=
typenamestd::enable_if<
74std::is_integral<T>::value, T>::type>
96: f(std::move(num.f)), s(std::move(num.s)) {}
104: f(std::move(high)), s(std::move(low)) {}
111 uint256_t(
constuint64_t high,
constuint64_t low) : f(high), s(low) {}
127 return128 + s._lez();
139 return128 + f._trz();
146 inline explicit operatorbool()
const{
returnf || s; }
153 template<
typenameT,
typename=
typenamestd::enable_if<
154std::is_integral<T>::value, T>::type>
155 inline explicit operatorT()
const{
156 return static_cast<T
>(s);
163 inline explicit operator uint128_t()
const{
returns; }
182 inlineuint256_t &
operator=(
constuint256_t &p) =
default;
190 template<
typenameT,
typename=
typenamestd::enable_if<
191std::is_integral<T>::value, T>::type>
210 inlineuint256_t &
operator=(uint256_t &&p) =
default;
218 template<
typenameT,
typename=
typenamestd::enable_if<
219std::is_integral<T>::value, T>::type>
221 boolapp = s + p < s;
222 returnuint256_t(f + app, s + p);
231 boolapp = (s + p.s < s);
232 return{f + app + p.f, s + p.s};
241 template<
typenameT,
typename=
typenamestd::enable_if<
242std::is_integral<T>::value, T>::type>
244 boolapp = (p + s < s);
256 boolapp = (s + p.s < s);
286 template<
typenameT,
typename=
typenamestd::enable_if<
287std::is_integral<T>::value, T>::type>
290 returnuint256_t(f - app, s - p);
300 return{f - p.f - app, s - p.s};
307 inlineuint256_t
operator-() {
return~*
this+ uint256_t(1); }
333 template<
typenameT,
typename=
typenamestd::enable_if<
334std::is_integral<T>::value, T>::type>
360 template<
typenameT,
typename=
typenamestd::enable_if<
361std::is_integral<T>::value, T>::type>
363 return*
this* uint256_t(p);
372 uint128_tf_first(s.upper()), f_second(s.lower()), s_first(p.s.
upper()),
373s_second(p.s.
lower());
374 uint128_tfi = f_first * s_first, se = f_first * s_second,
375th = s_first * f_second, fo = s_second * f_second;
376 uint128_ttmp = se << 64, tmp2 = th << 64;
377 intcc = (tmp + tmp2 < tmp);
379cc += (tmp + fo < tmp);
380 return{f * p.s + s * p.f + fi + se.
upper() + th.upper() + cc,
390 template<
typenameT,
typename=
typenamestd::enable_if<
391std::is_integral<T>::value, T>::type>
393 return(*
this*= uint256_t(p));
402 uint128_tf_first(s.upper()), f_second(s.lower()), s_first(p.s.
upper()),
403s_second(p.s.
lower());
404 uint128_tfi = f_first * s_first, se = f_first * s_second,
405th = s_first * f_second, fo = s_second * f_second;
406 uint128_ttmp = se << 64, tmp2 = th << 64;
407 intcc = (tmp + tmp2 < tmp);
409cc += (tmp + fo < tmp);
410f = f * p.s + s * p.f + fi + se.
upper() + th.upper() + cc;
421std::pair<uint256_t, uint256_t>
divide(
constuint256_t &p) {
423 return{uint256_t(0), *
this};
424}
else if(*
this== p) {
425 return{uint256_t(1), uint256_t(0)};
427uint256_t tmp = p, tmp2 = *
this;
428uint16_t left = tmp.
_lez() -
_lez();
430uint256_t quotient(0);
433uint16_t shf = tmp2._lez() - tmp.
_lez();
447 return{quotient << left, tmp2};
456 template<
typenameT,
typename=
typenamestd::enable_if<
457std::is_integral<T>::value, T>::type>
459uint256_t tmp = *
this;
477*
this=
divide(p).first;
487 template<
typenameT,
typename=
typenamestd::enable_if<
488std::is_integral<T>::value, T>::type>
490*
this/= uint256_t(p);
507 template<
typenameT,
typename=
typenamestd::enable_if<
508std::is_integral<T>::value, T>::type>
510uint256_t tmp = *
this;
521*
this=
divide(p).second;
531 template<
typenameT,
typename=
typenamestd::enable_if<
532std::is_integral<T>::value, T>::type>
534*
this%= uint256_t(p);
544 returnf < other.f || (f == other.f && s < other.s);
553 returnf < other.f || (f == other.f && s <= other.s);
562 returnf > other.f || (f == other.f && s > other.s);
571 return(f > other.f) || (f == other.f && s >= other.s);
580 returnf == other.f && s == other.s;
589 return!((*this) == other);
604 return(s || f) && (b.s || b.f);
613 return(s || f) || (b.s || b.f);
628 template<
typenameT,
typename=
typenamestd::enable_if<
629std::is_integral<T>::value, T>::type>
631 return*
this< uint256_t(other);
640 template<
typenameT,
typename=
typenamestd::enable_if<
641std::is_integral<T>::value, T>::type>
643 return*
this<= uint256_t(other);
652 template<
typenameT,
typename=
typenamestd::enable_if<
653std::is_integral<T>::value, T>::type>
655 return*
this> uint256_t(other);
664 template<
typenameT,
typename=
typenamestd::enable_if<
665std::is_integral<T>::value, T>::type>
667 return*
this>= uint256_t(other);
676 template<
typenameT,
typename=
typenamestd::enable_if<
677std::is_integral<T>::value, T>::type>
679 return*
this== uint256_t(other);
688 template<
typenameT,
typename=
typenamestd::enable_if<
689std::is_integral<T>::value, T>::type>
691 return*
this!= uint256_t(other);
700 template<
typenameT,
typename=
typenamestd::enable_if<
701std::is_integral<T>::value, T>::type>
703 return(s || f) && (b);
713 template<
typenameT,
typename=
typenamestd::enable_if<
714std::is_integral<T>::value, T>::type>
716 return(s || f) || (b);
731 template<
typenameT,
typename=
typenamestd::enable_if<
732std::is_integral<T>::value, T>::type>
735 return{this->f, this->s};
736}
else if(p >= 128) {
737 returnuint256_t((this->s << (p - 128)),
uint128_t(0));
739 returnuint256_t((this->f << p) + (this->s >> (128 - p)),
749 template<
typenameT,
typename=
typenamestd::enable_if<
750std::is_integral<T>::value, T>::type>
754this->f = (this->s << (p - 128));
757f = ((this->s >> (128 - p)) + (this->f << p));
770 template<
typenameT,
typename=
typenamestd::enable_if<
771std::is_integral<T>::value, T>::type>
774 return{this->f, this->s};
775}
else if(p >= 128) {
776 returnuint256_t(
uint128_t(0), (this->f >> (p - 128)));
778 returnuint256_t((this->f >> p),
779(this->s >> p) + (this->f << (128 - p)));
788 template<
typenameT,
typename=
typenamestd::enable_if<
789std::is_integral<T>::value, T>::type>
794s = (this->f >> (p - 128));
796s = (this->s >> p) + (this->f << (128 - p));
809 template<
typenameT,
typename=
typenamestd::enable_if<
810std::is_integral<T>::value, T>::type>
812 return*
this& uint256_t(p);
821 return{f & p.f, s & p.s};
841 template<
typenameT,
typename=
typenamestd::enable_if<
842std::is_integral<T>::value, T>::type>
854 template<
typenameT,
typename=
typenamestd::enable_if<
855std::is_integral<T>::value, T>::type>
857 return*
this| uint256_t(p);
866 return{this->f | p.f, this->s | p.s};
875 template<
typenameT,
typename=
typenamestd::enable_if<
876std::is_integral<T>::value, T>::type>
899 template<
typenameT,
typename=
typenamestd::enable_if<
900std::is_integral<T>::value, T>::type>
902 returnuint256_t(f, s ^ p);
911 return{this->f ^ p.f, this->s ^ p.s};
931 template<
typenameT,
typename=
typenamestd::enable_if<
932std::is_integral<T>::value, T>::type>
947 friendstd::ostream &
operator<<(std::ostream &op, uint256_t p) {
951std::string out =
"0", p_2 =
"1";
953 for(uint64_t i = 0; i < 128; ++i) {
955out =
add(out, p_2);
957p_2 =
add(p_2, p_2);
961 for(
inti = 0; i < 128; ++i) {
963out =
add(out, p_2);
965p_2 =
add(p_2, p_2);
975template<
typenameT,
typename=
typenamestd::enable_if<
976std::is_integral<T>::value, T>::type>
981template<
typenameT,
typename=
typenamestd::enable_if<
982std::is_integral<T>::value, T>::type>
987template<
typenameT,
typename=
typenamestd::enable_if<
988std::is_integral<T>::value, T>::type>
993template<
typenameT,
typename=
typenamestd::enable_if<
994std::is_integral<T>::value, T>::type>
999template<
typenameT,
typename=
typenamestd::enable_if<
1000std::is_integral<T>::value, T>::type>
1006template<
typenameT,
typename=
typenamestd::enable_if<
1007std::is_integral<T>::value, T>::type>
1012template<
typenameT,
typename=
typenamestd::enable_if<
1013std::is_integral<T>::value, T>::type>
1018template<
typenameT,
typename=
typenamestd::enable_if<
1019std::is_integral<T>::value, T>::type>
1025template<
typenameT,
typename=
typenamestd::enable_if<
1026std::is_integral<T>::value, T>::type>
1027inline booloperator&&(
constT p,
const uint256_t&q) {
1031template<
typenameT,
typename=
typenamestd::enable_if<
1032std::is_integral<T>::value, T>::type>
1033inline booloperator||(
constT p,
const uint256_t&q) {
1038template<
typenameT,
typename=
typenamestd::enable_if<
1039std::is_integral<T>::value, T>::type>
1040inline booloperator==(
constT p,
const uint256_t&q) {
1044template<
typenameT,
typename=
typenamestd::enable_if<
1045std::is_integral<T>::value, T>::type>
1046inline booloperator!=(
constT p,
const uint256_t&q) {
1050template<
typenameT,
typename=
typenamestd::enable_if<
1051std::is_integral<T>::value, T>::type>
1052inline booloperator<(
constT p,
const uint256_t&q) {
1056template<
typenameT,
typename=
typenamestd::enable_if<
1057std::is_integral<T>::value, T>::type>
1058inline booloperator<=(
constT p,
const uint256_t&q) {
1062template<
typenameT,
typename=
typenamestd::enable_if<
1063std::is_integral<T>::value, T>::type>
1064inline booloperator>(
constT p,
const uint256_t&q) {
1068template<
typenameT,
typename=
typenamestd::enable_if<
1069std::is_integral<T>::value, T>::type>
1070inline booloperator>=(
constT p,
const uint256_t&q) {
class for 128-bit unsigned integer
uint64_t upper() const
returns upper 64-bit integer part
uint64_t lower() const
returns lower 64-bit integer part
class for 256-bit unsigned integer
uint256_t(uint128_t high, uint128_t low)
Parameterized constructor.
bool operator!()
operator ! for uint256_t
uint32_t _lez()
Leading zeroes in binary.
uint256_t(uint256_t &&num) noexcept
Move constructor.
uint256_t & operator<<=(const T &p)
operator <<= for uint256_t
bool operator<=(const uint256_t &other)
operator <= for uint256_t
uint256_t(const std::string &str)
Parameterized constructor.
bool operator<=(const T &other)
operator <= for other types
uint256_t operator+(const T &p)
operator + for uint256_t and other integer types.
uint256_t operator--(int p)
operator – (post-decrement)
uint256_t(const uint64_t high, const uint64_t low)
Parameterized constructor.
uint256_t & operator%=(const uint256_t &p)
operator %= for uint256_t
uint256_t operator|(const uint256_t &p)
operator | for uint256_t (bitwise operator)
bool operator&&(const T &b)
operator && for other types
uint256_t & operator&=(const uint256_t &p)
operator &= for uint256_t (bitwise operator)
uint256_t & operator^=(const T &p)
operator ^= for other types (bitwise operator)
~uint256_t()=default
Destructor for uint256_t.
uint256_t operator-()
operator - using twos complement
bool operator||(const uint256_t &b)
operator || for uint256_t
uint256_t(const uint256_t &num)=default
Copy constructor.
uint256_t & operator*=(const uint256_t &p)
operator *= for uint256_t and other integer types.
uint256_t operator>>(const T &p)
operator >> for uint256_t
uint256_t operator<<(const T &p)
operator << for uint256_t
bool operator||(const T &b)
operator || for other types
uint256_t & operator=(const uint256_t &p)=default
operator = for uint256_t
uint256_t operator/(const uint256_t &p)
operator / for uint256_t and other integer types.
uint256_t & operator+=(const T &p)
operator += for uint256_t and other integer types.
uint256_t & operator-=(const uint256_t &p)
operator -= for uint256_t
uint256_t & operator=(uint256_t &&p)=default
Move assignment operator.
uint256_t operator&(const T &p)
operator & for other types (bitwise operator)
uint256_t operator~()
operator ~ for uint256_t
uint256_t operator^(const uint256_t &p)
operator ^ for uint256_t (bitwise operator)
uint256_t & operator%=(const T &p)
operator %= for uint256_t
bool operator()()
operator () for uint256_t
uint256_t operator++(int)
post-increment operator
uint256_t operator%(const T &p)
operator % for uint256_t and other integer types.
std::pair< uint256_t, uint256_t > divide(const uint256_t &p)
divide function for uint256_t and other integer types.
uint256_t & operator=(const std::string &p)
operator = for type string
uint256_t operator-(const T &p)
operator - for uint256_t and other integer types.
bool operator!=(const T &other)
operator != for other types
bool operator==(const uint256_t &other)
operator == for uint256_t
friend std::ostream & operator<<(std::ostream &op, uint256_t p)
operator << for printing uint256_t integer
bool operator==(const T &other)
operator == for other types
uint256_t operator&(const uint256_t &p)
operator & for uint256_t (bitwise operator)
uint32_t _trz()
Trailing zeroes in binary.
uint256_t & operator--()
operator – (pre-decrement)
bool operator&&(const uint256_t &b)
operator && for uint256_t
uint256_t & operator|=(const uint256_t &p)
operator |= for uint256_t (bitwise operator)
uint128_t lower() const
returns lower 128-bit integer part
uint256_t operator*(const uint256_t &p)
operator * for uint256_t and other integer types.
uint256_t operator*(const T &p)
operator * for uint256_t and other integer types.
bool operator!=(const uint256_t &other)
operator != for uint256_t
uint256_t operator-(const uint256_t &p)
operator - for uint256_t
uint256_t & operator/=(const T &p)
operator /= for uint256_t and other integer types.
uint256_t & operator/=(const uint256_t &p)
operator /= for uint256_t
bool operator<(const T &other)
operator < for other types
uint256_t & operator+=(const uint256_t &p)
operator += for uint256_t
uint256_t & operator^=(const uint256_t &p)
operator ^= for uint256_t (bitwise operator)
uint256_t operator/(const T &p)
operator / for uint256_t and other integer types.
bool operator>(const uint256_t &other)
operator > for uint256_t
uint256_t operator^(const T &p)
operator ^ for other types (bitwise operator)
uint256_t operator-=(const T p)
operator -= for uint256_t and other integer types.
uint256_t operator|(const T &p)
operator | for other types (bitwise operator)
uint256_t operator%(const uint256_t &p)
operator % for uint256_t
bool operator>(const T &other)
operator > for other types
uint256_t & operator>>=(const T &p)
operator >>= for uint256_t
uint256_t & operator=(const T &p)
operator = for other types
bool operator>=(const uint256_t &other)
operator >= for uint256_t
uint128_t upper() const
returns upper 128-bit integer part
uint256_t(T low)
Parameterized constructor.
uint256_t & operator|=(const T &p)
operator |= for other types (bitwise operator)
uint256_t & operator++()
pre-increment operator
uint256_t operator+(const uint256_t &p)
operator + for uint256_t and other integer types.
uint256_t & operator*=(const T &p)
operator *= for uint256_t and other integer types.
uint256_t & operator&=(const T p)
operator &= for other types (bitwise operator)
bool operator<(const uint256_t &other)
operator < for uint256_t
void __get_integer_from_string(const std::string &str)
First and second half of 256 bit number.
bool operator>=(const T &other)
operator >= for other types
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