Algorithms_in_C++  1.0.0
Set of algorithms implemented in C++.
uint256_t Class Reference

class for 256-bit unsigned integer More...

#include <uint256_t.hpp>

Collaboration diagram for uint256_t:
[legend]

Public Member Functions

template<typename T , typename = typename std::enable_if< std::is_integral<T>::value, T>::type>
 uint256_t (T low)
 Parameterized constructor. More...
 
 uint256_t (const std::string &str)
 Parameterized constructor. More...
 
 uint256_t (const uint256_t &num)=default
 Copy constructor. More...
 
 uint256_t (uint256_t &&num) noexcept
 Move constructor. More...
 
 uint256_t (uint128_t high, uint128_t low)
 Parameterized constructor. More...
 
 uint256_t (const uint64_t high, const uint64_t low)
 Parameterized constructor. More...
 
 ~uint256_t ()=default
 Destructor for uint256_t.
 
uint32_t _lez ()
 Leading zeroes in binary. More...
 
uint32_t _trz ()
 Trailing zeroes in binary. More...
 
 operator bool () const
 casting operator to boolean value More...
 
template<typename T , typename = typename std::enable_if< std::is_integral<T>::value, T>::type>
 operator T () const
 casting operator to any integer value More...
 
 operator uint128_t () const
 casting operator to uint128_t More...
 
uint128_t lower () const
 returns lower 128-bit integer part More...
 
uint128_t upper () const
 returns upper 128-bit integer part More...
 
uint256_toperator= (const uint256_t &p)=default
 operator = for uint256_t More...
 
template<typename T , typename = typename std::enable_if< std::is_integral<T>::value, T>::type>
uint256_toperator= (const T &p)
 operator = for other types More...
 
uint256_toperator= (const std::string &p)
 operator = for type string More...
 
uint256_toperator= (uint256_t &&p)=default
 Move assignment operator.
 
template<typename T , typename = typename std::enable_if< std::is_integral<T>::value, T>::type>
uint256_t operator+ (const T &p)
 operator + for uint256_t and other integer types. More...
 
uint256_t operator+ (const uint256_t &p)
 operator + for uint256_t and other integer types. More...
 
template<typename T , typename = typename std::enable_if< std::is_integral<T>::value, T>::type>
uint256_toperator+= (const T &p)
 operator += for uint256_t and other integer types. More...
 
uint256_toperator+= (const uint256_t &p)
 operator += for uint256_t More...
 
uint256_toperator++ ()
 pre-increment operator More...
 
uint256_t operator++ (int)
 post-increment operator More...
 
template<typename T , typename = typename std::enable_if< std::is_integral<T>::value, T>::type>
uint256_t operator- (const T &p)
 operator - for uint256_t and other integer types. More...
 
uint256_t operator- (const uint256_t &p)
 operator - for uint256_t More...
 
uint256_t operator- ()
 operator - using twos complement More...
 
uint256_toperator-- ()
 operator – (pre-decrement) More...
 
uint256_t operator-- (int p)
 operator – (post-decrement) More...
 
template<typename T , typename = typename std::enable_if< std::is_integral<T>::value, T>::type>
uint256_t operator-= (const T p)
 operator -= for uint256_t and other integer types. More...
 
uint256_toperator-= (const uint256_t &p)
 operator -= for uint256_t More...
 
template<typename T , typename = typename std::enable_if< std::is_integral<T>::value, T>::type>
uint256_t operator* (const T &p)
 operator * for uint256_t and other integer types. More...
 
uint256_t operator* (const uint256_t &p)
 operator * for uint256_t and other integer types. More...
 
template<typename T , typename = typename std::enable_if< std::is_integral<T>::value, T>::type>
uint256_toperator*= (const T &p)
 operator *= for uint256_t and other integer types. More...
 
uint256_toperator*= (const uint256_t &p)
 operator *= for uint256_t and other integer types. More...
 
std::pair< uint256_t, uint256_tdivide (const uint256_t &p)
 divide function for uint256_t and other integer types. More...
 
template<typename T , typename = typename std::enable_if< std::is_integral<T>::value, T>::type>
uint256_t operator/ (const T &p)
 operator / for uint256_t and other integer types. More...
 
uint256_t operator/ (const uint256_t &p)
 operator / for uint256_t and other integer types. More...
 
uint256_toperator/= (const uint256_t &p)
 operator /= for uint256_t More...
 
template<typename T , typename = typename std::enable_if< std::is_integral<T>::value, T>::type>
uint256_toperator/= (const T &p)
 operator /= for uint256_t and other integer types. More...
 
uint256_t operator% (const uint256_t &p)
 operator % for uint256_t More...
 
template<typename T , typename = typename std::enable_if< std::is_integral<T>::value, T>::type>
uint256_t operator% (const T &p)
 operator % for uint256_t and other integer types. More...
 
uint256_toperator%= (const uint256_t &p)
 operator %= for uint256_t More...
 
template<typename T , typename = typename std::enable_if< std::is_integral<T>::value, T>::type>
uint256_toperator%= (const T &p)
 operator %= for uint256_t More...
 
bool operator< (const uint256_t &other)
 operator < for uint256_t More...
 
bool operator<= (const uint256_t &other)
 operator <= for uint256_t More...
 
bool operator> (const uint256_t &other)
 operator > for uint256_t More...
 
bool operator>= (const uint256_t &other)
 operator >= for uint256_t More...
 
bool operator== (const uint256_t &other)
 operator == for uint256_t More...
 
bool operator!= (const uint256_t &other)
 operator != for uint256_t More...
 
bool operator! ()
 operator ! for uint256_t More...
 
bool operator&& (const uint256_t &b)
 operator && for uint256_t More...
 
bool operator|| (const uint256_t &b)
 operator || for uint256_t More...
 
bool operator() ()
 operator () for uint256_t More...
 
template<typename T , typename = typename std::enable_if< std::is_integral<T>::value, T>::type>
bool operator< (const T &other)
 operator < for other types More...
 
template<typename T , typename = typename std::enable_if< std::is_integral<T>::value, T>::type>
bool operator<= (const T &other)
 operator <= for other types More...
 
template<typename T , typename = typename std::enable_if< std::is_integral<T>::value, T>::type>
bool operator> (const T &other)
 operator > for other types More...
 
template<typename T , typename = typename std::enable_if< std::is_integral<T>::value, T>::type>
bool operator>= (const T &other)
 operator >= for other types More...
 
template<typename T , typename = typename std::enable_if< std::is_integral<T>::value, T>::type>
bool operator== (const T &other)
 operator == for other types More...
 
template<typename T , typename = typename std::enable_if< std::is_integral<T>::value, T>::type>
bool operator!= (const T &other)
 operator != for other types More...
 
template<typename T , typename = typename std::enable_if< std::is_integral<T>::value, T>::type>
bool operator&& (const T &b)
 operator && for other types More...
 
template<typename T , typename = typename std::enable_if< std::is_integral<T>::value, T>::type>
bool operator|| (const T &b)
 operator || for other types More...
 
uint256_t operator~ ()
 operator ~ for uint256_t More...
 
template<typename T , typename = typename std::enable_if< std::is_integral<T>::value, T>::type>
uint256_t operator<< (const T &p)
 operator << for uint256_t More...
 
template<typename T , typename = typename std::enable_if< std::is_integral<T>::value, T>::type>
uint256_toperator<<= (const T &p)
 operator <<= for uint256_t More...
 
template<typename T , typename = typename std::enable_if< std::is_integral<T>::value, T>::type>
uint256_t operator>> (const T &p)
 operator >> for uint256_t More...
 
template<typename T , typename = typename std::enable_if< std::is_integral<T>::value, T>::type>
uint256_toperator>>= (const T &p)
 operator >>= for uint256_t More...
 
template<typename T , typename = typename std::enable_if< std::is_integral<T>::value, T>::type>
uint256_t operator& (const T &p)
 operator & for other types (bitwise operator) More...
 
uint256_t operator& (const uint256_t &p)
 operator & for uint256_t (bitwise operator) More...
 
uint256_toperator&= (const uint256_t &p)
 operator &= for uint256_t (bitwise operator) More...
 
template<typename T , typename = typename std::enable_if< std::is_integral<T>::value, T>::type>
uint256_toperator&= (const T p)
 operator &= for other types (bitwise operator) More...
 
template<typename T , typename = typename std::enable_if< std::is_integral<T>::value, T>::type>
uint256_t operator| (const T &p)
 operator | for other types (bitwise operator) More...
 
uint256_t operator| (const uint256_t &p)
 operator | for uint256_t (bitwise operator) More...
 
template<typename T , typename = typename std::enable_if< std::is_integral<T>::value, T>::type>
uint256_toperator|= (const T &p)
 operator |= for other types (bitwise operator) More...
 
uint256_toperator|= (const uint256_t &p)
 operator |= for uint256_t (bitwise operator) More...
 
template<typename T , typename = typename std::enable_if< std::is_integral<T>::value, T>::type>
uint256_t operator^ (const T &p)
 operator ^ for other types (bitwise operator) More...
 
uint256_t operator^ (const uint256_t &p)
 operator ^ for uint256_t (bitwise operator) More...
 
uint256_toperator^= (const uint256_t &p)
 operator ^= for uint256_t (bitwise operator) More...
 
template<typename T , typename = typename std::enable_if< std::is_integral<T>::value, T>::type>
uint256_toperator^= (const T &p)
 operator ^= for other types (bitwise operator) More...
 

Private Member Functions

void __get_integer_from_string (const std::string &str)
 First and second half of 256 bit number. More...
 

Private Attributes

uint128_t f {}
 
uint128_t s {}
 

Friends

std::ostreamoperator<< (std::ostream &op, uint256_t p)
 operator << for printing uint256_t integer More...
 

Detailed Description

class for 256-bit unsigned integer

Constructor & Destructor Documentation

◆ uint256_t() [1/6]

template<typename T , typename = typename std::enable_if< std::is_integral<T>::value, T>::type>
uint256_t::uint256_t ( low)
inlineexplicit

Parameterized constructor.

Template Parameters
Ttemplate for integer types
Parameters
lowInteger denoting lower 128-bits
75 : s(low), f(0) {}

◆ uint256_t() [2/6]

uint256_t::uint256_t ( const std::string str)
inlineexplicit

Parameterized constructor.

Parameters
strInteger string (hexadecimal starting with 0x.. or decimal)
81  {
83  }
void __get_integer_from_string(const std::string &str)
First and second half of 256 bit number.
Definition: uint256_t.hpp:43
Here is the call graph for this function:

◆ uint256_t() [3/6]

uint256_t::uint256_t ( const uint256_t num)
default

Copy constructor.

Parameters
num256-bit unsigned integer

◆ uint256_t() [4/6]

uint256_t::uint256_t ( uint256_t &&  num)
inlinenoexcept

Move constructor.

Parameters
num256-bit unsigned integer
96  : f(std::move(num.f)), s(std::move(num.s)) {}
T move(T... args)

◆ uint256_t() [5/6]

uint256_t::uint256_t ( uint128_t  high,
uint128_t  low 
)
inline

Parameterized constructor.

Parameters
highhigher part 128-bit unsigned integer
lowlower part 128-bit unsigned integer
104  : f(std::move(high)), s(std::move(low)) {}

◆ uint256_t() [6/6]

uint256_t::uint256_t ( const uint64_t  high,
const uint64_t  low 
)
inline

Parameterized constructor.

Parameters
highhigher part 64-bit unsigned integer
lowlower part 64-bit unsigned integer
111 : f(high), s(low) {}

Member Function Documentation

◆ __get_integer_from_string()

void uint256_t::__get_integer_from_string ( const std::string str)
inlineprivate

First and second half of 256 bit number.

Get integer from given string.

Create an integer from a given string

Parameters
strinteger string, can be hexadecimal (starting on 0x... or number)
Returns
void
43  {
44  this->f = this->s = uint128_t(0);
45  if (str.size() > 1 && str[1] == 'x') {
46  for (auto i = 2; i < str.size(); ++i) {
47  *this *= 16LL;
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);
54  }
55  }
56  } else {
57  for (auto &x : str) {
58  *this *= 10LL;
59  *this += (x - '0');
60  }
61  }
62  }
class for 128-bit unsigned integer
Definition: uint128_t.hpp:59
T size(T... args)
Here is the call graph for this function:

◆ _lez()

uint32_t uint256_t::_lez ( )
inline

Leading zeroes in binary.

Calculates leading zeros in 256-bit integer

Returns
Integer denoting leading zeroes
123  {
124  if (f) {
125  return f._lez();
126  }
127  return 128 + s._lez();
128  }
uint32_t _lez()
Leading zeroes in binary.
Definition: uint128_t.hpp:139
Here is the call graph for this function:

◆ _trz()

uint32_t uint256_t::_trz ( )
inline

Trailing zeroes in binary.

Calculates leading zeros in 256-bit integer

Returns
Integer denoting Trailing zeroes
135  {
136  if (s) {
137  return s._trz();
138  }
139  return 128 + f._trz();
140  }
uint32_t _trz()
Trailing zeroes in binary.
Definition: uint128_t.hpp:162
Here is the call graph for this function:

◆ divide()

std::pair<uint256_t, uint256_t> uint256_t::divide ( const uint256_t p)
inline

divide function for uint256_t and other integer types.

divide this value and

Parameters
p256-bit unsigned integer
Returns
pair denoting quotient and remainder.
421  {
422  if (*this < p) { // if this is less than divisor
423  return {uint256_t(0), *this};
424  } else if (*this == p) { // if this is equal to divisor
425  return {uint256_t(1), uint256_t(0)};
426  }
427  uint256_t tmp = p, tmp2 = *this;
428  uint16_t left = tmp._lez() - _lez();
429  tmp <<= left;
430  uint256_t quotient(0);
431  uint256_t zero(0);
432  while (left >= 0 && tmp2 >= p) {
433  uint16_t shf = tmp2._lez() - tmp._lez();
434  if (shf) {
435  tmp >>= shf;
436  quotient <<= shf;
437  left -= shf;
438  }
439  if (tmp2 < tmp) {
440  tmp >>= 1;
441  quotient <<= 1;
442  --left;
443  }
444  tmp2 -= tmp;
445  ++quotient;
446  }
447  return {quotient << left, tmp2};
448  }
class for 256-bit unsigned integer
Definition: uint256_t.hpp:33
uint32_t _lez()
Leading zeroes in binary.
Definition: uint256_t.hpp:123
T left(T... args)
Here is the call graph for this function:

◆ lower()

uint128_t uint256_t::lower ( ) const
inline

returns lower 128-bit integer part

Returns
returns lower 128-bit integer part
169 { return s; }

◆ operator bool()

uint256_t::operator bool ( ) const
inlineexplicit

casting operator to boolean value

Returns
true if value of this is non-zero, else false
146 { return f || s; }

◆ operator T()

template<typename T , typename = typename std::enable_if< std::is_integral<T>::value, T>::type>
uint256_t::operator T ( ) const
inlineexplicit

casting operator to any integer value

Template Parameters
Tany integer type
Returns
integer value casted to mentioned type
155  {
156  return static_cast<T>(s);
157  }

◆ operator uint128_t()

uint256_t::operator uint128_t ( ) const
inlineexplicit

casting operator to uint128_t

Returns
returns lower 128-bit integer part
163 { return s; }

◆ operator!()

bool uint256_t::operator! ( )
inline

operator ! for uint256_t

Returns
true if this has zero value, else false
596 { return !f && !s; }

◆ operator!=() [1/2]

template<typename T , typename = typename std::enable_if< std::is_integral<T>::value, T>::type>
bool uint256_t::operator!= ( const T &  other)
inline

operator != for other types

Template Parameters
Tintegral type
Parameters
othernumber to be compared with this
Returns
true if this is not equal to other, else false
690  {
691  return *this != uint256_t(other);
692  }

◆ operator!=() [2/2]

bool uint256_t::operator!= ( const uint256_t other)
inline

operator != for uint256_t

Parameters
othernumber to be compared with this
Returns
true if this is not equal than other, else false
588  {
589  return !((*this) == other);
590  }

◆ operator%() [1/2]

template<typename T , typename = typename std::enable_if< std::is_integral<T>::value, T>::type>
uint256_t uint256_t::operator% ( const T &  p)
inline

operator % for uint256_t and other integer types.

Template Parameters
Tdenoting integral type
Parameters
pa type of integer variable
Returns
unsigned 256-bit remainder.
509  {
510  uint256_t tmp = *this;
511  tmp %= uint256_t(p);
512  return tmp;
513  }

◆ operator%() [2/2]

uint256_t uint256_t::operator% ( const uint256_t p)
inline

operator % for uint256_t

Parameters
p256-bit unsigned integer
Returns
unsigned 256-bit remainder.
499 { return divide(p).second; }
std::pair< uint256_t, uint256_t > divide(const uint256_t &p)
divide function for uint256_t and other integer types.
Definition: uint256_t.hpp:421
Here is the call graph for this function:

◆ operator%=() [1/2]

template<typename T , typename = typename std::enable_if< std::is_integral<T>::value, T>::type>
uint256_t& uint256_t::operator%= ( const T &  p)
inline

operator %= for uint256_t

Template Parameters
Tdenoting integral type
Parameters
pa type of integer variable
Returns
this set as unsigned 256-bit remainder.
533  {
534  *this %= uint256_t(p);
535  return *this;
536  }

◆ operator%=() [2/2]

uint256_t& uint256_t::operator%= ( const uint256_t p)
inline

operator %= for uint256_t

Parameters
p256-bit unsigned integer
Returns
this set as unsigned 256-bit remainder.
520  {
521  *this = divide(p).second;
522  return *this;
523  }
Here is the call graph for this function:

◆ operator&() [1/2]

template<typename T , typename = typename std::enable_if< std::is_integral<T>::value, T>::type>
uint256_t uint256_t::operator& ( const T &  p)
inline

operator & for other types (bitwise operator)

Template Parameters
Tintegral type
Parameters
pnumber to be operated
Returns
value of this & p (& is bit-wise operator)
811  {
812  return *this & uint256_t(p);
813  }

◆ operator&() [2/2]

uint256_t uint256_t::operator& ( const uint256_t p)
inline

operator & for uint256_t (bitwise operator)

Parameters
pnumber to be operated
Returns
value of this & p (& is bit-wise operator)
820  {
821  return {f & p.f, s & p.s};
822  }

◆ operator&&() [1/2]

template<typename T , typename = typename std::enable_if< std::is_integral<T>::value, T>::type>
bool uint256_t::operator&& ( const T &  b)
inline

operator && for other types

Template Parameters
Tintegral type
Parameters
othernumber to be compared with this
Returns
true if this is both values are non-zero, else false
702  {
703  return (s || f) && (b);
704  }

◆ operator&&() [2/2]

bool uint256_t::operator&& ( const uint256_t b)
inline

operator && for uint256_t

Parameters
bnumber to be compared with this
Returns
true if both of the values are not zero, else false
603  {
604  return (s || f) && (b.s || b.f);
605  }

◆ operator&=() [1/2]

template<typename T , typename = typename std::enable_if< std::is_integral<T>::value, T>::type>
uint256_t& uint256_t::operator&= ( const T  p)
inline

operator &= for other types (bitwise operator)

Template Parameters
Tintegral type
Parameters
pnumber to be operated
Returns
this = this & p (& is bit-wise operator)
843  {
844  s &= p.s;
845  return *this;
846  }

◆ operator&=() [2/2]

uint256_t& uint256_t::operator&= ( const uint256_t p)
inline

operator &= for uint256_t (bitwise operator)

Parameters
pnumber to be operated
Returns
this = this & p (& is bit-wise operator)
829  {
830  f &= p.f;
831  s &= p.s;
832  return *this;
833  }

◆ operator()()

bool uint256_t::operator() ( )
inline

operator () for uint256_t

Returns
true if this value is non-zero, else false
620 { return s || f; }

◆ operator*() [1/2]

template<typename T , typename = typename std::enable_if< std::is_integral<T>::value, T>::type>
uint256_t uint256_t::operator* ( const T &  p)
inline

operator * for uint256_t and other integer types.

Template Parameters
Tdenoting integral type
Parameters
pa type of integer variable
Returns
multiplication of this and p, returning uint256_t integer
362  {
363  return *this * uint256_t(p);
364  }

◆ operator*() [2/2]

uint256_t uint256_t::operator* ( const uint256_t p)
inline

operator * for uint256_t and other integer types.

Parameters
p256-bit unsigned integer
Returns
multiplication of this and p, returning uint256_t integer
371  {
372  uint128_t f_first(s.upper()), f_second(s.lower()), s_first(p.s.upper()),
373  s_second(p.s.lower());
374  uint128_t fi = f_first * s_first, se = f_first * s_second,
375  th = s_first * f_second, fo = s_second * f_second;
376  uint128_t tmp = se << 64, tmp2 = th << 64;
377  int cc = (tmp + tmp2 < tmp);
378  tmp += tmp2;
379  cc += (tmp + fo < tmp);
380  return {f * p.s + s * p.f + fi + se.upper() + th.upper() + cc,
381  tmp + fo};
382  }
uint64_t upper() const
returns upper 64-bit integer part
Definition: uint128_t.hpp:207
uint64_t lower() const
returns lower 64-bit integer part
Definition: uint128_t.hpp:201
Here is the call graph for this function:

◆ operator*=() [1/2]

template<typename T , typename = typename std::enable_if< std::is_integral<T>::value, T>::type>
uint256_t& uint256_t::operator*= ( const T &  p)
inline

operator *= for uint256_t and other integer types.

Template Parameters
Tdenoting integral type
Parameters
pa type of integer variable
Returns
multiplication of this and p, returning this
392  {
393  return (*this *= uint256_t(p));
394  }

◆ operator*=() [2/2]

uint256_t& uint256_t::operator*= ( const uint256_t p)
inline

operator *= for uint256_t and other integer types.

Parameters
p256-bit unsigned integer
Returns
multiplication of this and p, returning this
401  {
402  uint128_t f_first(s.upper()), f_second(s.lower()), s_first(p.s.upper()),
403  s_second(p.s.lower());
404  uint128_t fi = f_first * s_first, se = f_first * s_second,
405  th = s_first * f_second, fo = s_second * f_second;
406  uint128_t tmp = se << 64, tmp2 = th << 64;
407  int cc = (tmp + tmp2 < tmp);
408  tmp += tmp2;
409  cc += (tmp + fo < tmp);
410  f = f * p.s + s * p.f + fi + se.upper() + th.upper() + cc;
411  s = tmp + fo;
412  return *this;
413  }
Here is the call graph for this function:

◆ operator+() [1/2]

template<typename T , typename = typename std::enable_if< std::is_integral<T>::value, T>::type>
uint256_t uint256_t::operator+ ( const T &  p)
inline

operator + for uint256_t and other integer types.

Template Parameters
Tdenoting integral type
Parameters
pa type of integer variable
Returns
addition of this and p, returning uint256_t integer
220  {
221  bool app = s + p < s;
222  return uint256_t(f + app, s + p);
223  }

◆ operator+() [2/2]

uint256_t uint256_t::operator+ ( const uint256_t p)
inline

operator + for uint256_t and other integer types.

Parameters
p256-bit unsigned integer
Returns
addition of this and p, returning uint256_t integer
230  {
231  bool app = (s + p.s < s);
232  return {f + app + p.f, s + p.s};
233  }

◆ operator++() [1/2]

uint256_t& uint256_t::operator++ ( )
inline

pre-increment operator

Returns
incremented value of this.
266  {
267  *this += 1;
268  return *this;
269  }

◆ operator++() [2/2]

uint256_t uint256_t::operator++ ( int  )
inline

post-increment operator

Returns
incremented value of this.
275  {
276  ++*this;
277  return *this;
278  }

◆ operator+=() [1/2]

template<typename T , typename = typename std::enable_if< std::is_integral<T>::value, T>::type>
uint256_t& uint256_t::operator+= ( const T &  p)
inline

operator += for uint256_t and other integer types.

Template Parameters
Tdenoting integral type
Parameters
pa type of integer variable
Returns
addition of this and p, returning this
243  {
244  bool app = (p + s < s);
245  this->f += app;
246  this->s += p;
247  return *this;
248  }

◆ operator+=() [2/2]

uint256_t& uint256_t::operator+= ( const uint256_t p)
inline

operator += for uint256_t

Parameters
p256-bit unsigned integer
Returns
addition of this and p, returning this
255  {
256  bool app = (s + p.s < s);
257  f = f + app + p.f;
258  s = s + p.s;
259  return *this;
260  }

◆ operator-() [1/3]

uint256_t uint256_t::operator- ( )
inline

operator - using twos complement

Returns
2's complement of this.
307 { return ~*this + uint256_t(1); }

◆ operator-() [2/3]

template<typename T , typename = typename std::enable_if< std::is_integral<T>::value, T>::type>
uint256_t uint256_t::operator- ( const T &  p)
inline

operator - for uint256_t and other integer types.

Template Parameters
Tdenoting integral type
Parameters
pa type of integer variable
Returns
subtraction of this and p, returning uint256_t integer
288  {
289  bool app = (p > s);
290  return uint256_t(f - app, s - p);
291  }

◆ operator-() [3/3]

uint256_t uint256_t::operator- ( const uint256_t p)
inline

operator - for uint256_t

Parameters
pa type of integer variable
Returns
subtraction of this and p, returning uint256_t integer
298  {
299  bool app = s < p.s;
300  return {f - p.f - app, s - p.s};
301  }

◆ operator--() [1/2]

uint256_t& uint256_t::operator-- ( )
inline

operator – (pre-decrement)

Returns
decremented value of this
313  {
314  *this -= 1;
315  return *this;
316  }

◆ operator--() [2/2]

uint256_t uint256_t::operator-- ( int  p)
inline

operator – (post-decrement)

Returns
decremented value of this
322  {
323  --*this;
324  return *this;
325  }

◆ operator-=() [1/2]

template<typename T , typename = typename std::enable_if< std::is_integral<T>::value, T>::type>
uint256_t uint256_t::operator-= ( const T  p)
inline

operator -= for uint256_t and other integer types.

Template Parameters
Tdenoting integral type
Parameters
pa type of integer variable
Returns
subtraction of this and p, returning this
335  {
336  bool app = (p > s);
337  f = f - app;
338  s = s - p;
339  return *this;
340  }

◆ operator-=() [2/2]

uint256_t& uint256_t::operator-= ( const uint256_t p)
inline

operator -= for uint256_t

Parameters
p256-bit unsigned integer
Returns
subtraction of this and p, returning this
347  {
348  bool app = s < p.s;
349  f = f - app - p.f;
350  s = s - p.s;
351  return *this;
352  }

◆ operator/() [1/2]

template<typename T , typename = typename std::enable_if< std::is_integral<T>::value, T>::type>
uint256_t uint256_t::operator/ ( const T &  p)
inline

operator / for uint256_t and other integer types.

Template Parameters
Tdenoting integral type
Parameters
pa type of integer variable
Returns
unsigned 256-bit quotient.
458  {
459  uint256_t tmp = *this;
460  tmp /= uint256_t(p);
461  return tmp;
462  }

◆ operator/() [2/2]

uint256_t uint256_t::operator/ ( const uint256_t p)
inline

operator / for uint256_t and other integer types.

Parameters
p256-bit unsigned integer
Returns
unsigned 256-bit quotient.
469 { return divide(p).first; }
Here is the call graph for this function:

◆ operator/=() [1/2]

template<typename T , typename = typename std::enable_if< std::is_integral<T>::value, T>::type>
uint256_t& uint256_t::operator/= ( const T &  p)
inline

operator /= for uint256_t and other integer types.

Template Parameters
Tdenoting integral type
Parameters
pa type of integer variable
Returns
this set as unsigned 256-bit quotient.
489  {
490  *this /= uint256_t(p);
491  return *this;
492  }

◆ operator/=() [2/2]

uint256_t& uint256_t::operator/= ( const uint256_t p)
inline

operator /= for uint256_t

Parameters
p256-bit unsigned integer
Returns
this set as unsigned 256-bit quotient.
476  {
477  *this = divide(p).first;
478  return *this;
479  }
Here is the call graph for this function:

◆ operator<() [1/2]

template<typename T , typename = typename std::enable_if< std::is_integral<T>::value, T>::type>
bool uint256_t::operator< ( const T &  other)
inline

operator < for other types

Template Parameters
Tintegral type
Parameters
othernumber to be compared with this
Returns
true if this is less than other, else false
630  {
631  return *this < uint256_t(other);
632  }

◆ operator<() [2/2]

bool uint256_t::operator< ( const uint256_t other)
inline

operator < for uint256_t

Parameters
othernumber to be compared with this
Returns
true if this is less than other, else false
543  {
544  return f < other.f || (f == other.f && s < other.s);
545  }

◆ operator<<()

template<typename T , typename = typename std::enable_if< std::is_integral<T>::value, T>::type>
uint256_t uint256_t::operator<< ( const T &  p)
inline

operator << for uint256_t

Template Parameters
Tintegral type
Parameters
pnumber denoting number of shifts
Returns
value of this shifted by p to left
733  {
734  if (!p) {
735  return {this->f, this->s};
736  } else if (p >= 128) {
737  return uint256_t((this->s << (p - 128)), uint128_t(0));
738  }
739  return uint256_t((this->f << p) + (this->s >> (128 - p)),
740  (this->s << p));
741  }

◆ operator<<=()

template<typename T , typename = typename std::enable_if< std::is_integral<T>::value, T>::type>
uint256_t& uint256_t::operator<<= ( const T &  p)
inline

operator <<= for uint256_t

Template Parameters
Tintegral type
Parameters
pnumber denoting number of shifts
Returns
this shifted by p to left
751  {
752  if (p) {
753  if (p >= 128) {
754  this->f = (this->s << (p - 128));
755  this->s = uint128_t(0);
756  } else {
757  f = ((this->s >> (128 - p)) + (this->f << p));
758  s = (this->s << p);
759  }
760  }
761  return *this;
762  }

◆ operator<=() [1/2]

template<typename T , typename = typename std::enable_if< std::is_integral<T>::value, T>::type>
bool uint256_t::operator<= ( const T &  other)
inline

operator <= for other types

Template Parameters
Tintegral type
Parameters
othernumber to be compared with this
Returns
true if this is less than or equal to other, else false
642  {
643  return *this <= uint256_t(other);
644  }

◆ operator<=() [2/2]

bool uint256_t::operator<= ( const uint256_t other)
inline

operator <= for uint256_t

Parameters
othernumber to be compared with this
Returns
true if this is less than or equal to other, else false
552  {
553  return f < other.f || (f == other.f && s <= other.s);
554  }

◆ operator=() [1/3]

uint256_t& uint256_t::operator= ( const std::string p)
inline

operator = for type string

Parameters
pa string to assign it's value to equivalent integer
Returns
this pointer with it's value equal to p
202  {
204  return *this;
205  }
Here is the call graph for this function:

◆ operator=() [2/3]

template<typename T , typename = typename std::enable_if< std::is_integral<T>::value, T>::type>
uint256_t& uint256_t::operator= ( const T &  p)
inline

operator = for other types

Template Parameters
Tdenoting any integer type
Parameters
pan integer to assign it's value
Returns
this pointer with it's value equal to p
192  {
193  this->s = p;
194  return *this;
195  }

◆ operator=() [3/3]

uint256_t& uint256_t::operator= ( const uint256_t p)
inlinedefault

operator = for uint256_t

Parameters
pan 256-bit integer to assign it's value
Returns
this pointer with it's value equal to p

◆ operator==() [1/2]

template<typename T , typename = typename std::enable_if< std::is_integral<T>::value, T>::type>
bool uint256_t::operator== ( const T &  other)
inline

operator == for other types

Template Parameters
Tintegral type
Parameters
othernumber to be compared with this
Returns
true if this is equal to other, else false
678  {
679  return *this == uint256_t(other);
680  }

◆ operator==() [2/2]

bool uint256_t::operator== ( const uint256_t other)
inline

operator == for uint256_t

Parameters
othernumber to be compared with this
Returns
true if this is equal than other, else false
579  {
580  return f == other.f && s == other.s;
581  }

◆ operator>() [1/2]

template<typename T , typename = typename std::enable_if< std::is_integral<T>::value, T>::type>
bool uint256_t::operator> ( const T &  other)
inline

operator > for other types

Template Parameters
Tintegral type
Parameters
othernumber to be compared with this
Returns
true if this is greater than other, else false
654  {
655  return *this > uint256_t(other);
656  }

◆ operator>() [2/2]

bool uint256_t::operator> ( const uint256_t other)
inline

operator > for uint256_t

Parameters
othernumber to be compared with this
Returns
true if this is greater than other, else false
561  {
562  return f > other.f || (f == other.f && s > other.s);
563  }

◆ operator>=() [1/2]

template<typename T , typename = typename std::enable_if< std::is_integral<T>::value, T>::type>
bool uint256_t::operator>= ( const T &  other)
inline

operator >= for other types

Template Parameters
Tintegral type
Parameters
othernumber to be compared with this
Returns
true if this is greater than or equal other, else false
666  {
667  return *this >= uint256_t(other);
668  }

◆ operator>=() [2/2]

bool uint256_t::operator>= ( const uint256_t other)
inline

operator >= for uint256_t

Parameters
othernumber to be compared with this
Returns
true if this is greater than or equal than other, else false
570  {
571  return (f > other.f) || (f == other.f && s >= other.s);
572  }

◆ operator>>()

template<typename T , typename = typename std::enable_if< std::is_integral<T>::value, T>::type>
uint256_t uint256_t::operator>> ( const T &  p)
inline

operator >> for uint256_t

Template Parameters
Tintegral type
Parameters
pnumber denoting number of shifts
Returns
value of this shifted by p to right
772  {
773  if (!p) {
774  return {this->f, this->s};
775  } else if (p >= 128) {
776  return uint256_t(uint128_t(0), (this->f >> (p - 128)));
777  }
778  return uint256_t((this->f >> p),
779  (this->s >> p) + (this->f << (128 - p)));
780  }

◆ operator>>=()

template<typename T , typename = typename std::enable_if< std::is_integral<T>::value, T>::type>
uint256_t& uint256_t::operator>>= ( const T &  p)
inline

operator >>= for uint256_t

Template Parameters
Tintegral type
Parameters
pnumber denoting number of shifts
Returns
this shifted by p to right
790  {
791  if (p) {
792  if (p >= 128) {
793  f = uint128_t(0);
794  s = (this->f >> (p - 128));
795  } else {
796  s = (this->s >> p) + (this->f << (128 - p));
797  f = (this->f >> p);
798  }
799  }
800  return *this;
801  }

◆ operator^() [1/2]

template<typename T , typename = typename std::enable_if< std::is_integral<T>::value, T>::type>
uint256_t uint256_t::operator^ ( const T &  p)
inline

operator ^ for other types (bitwise operator)

Template Parameters
Tintegral type
Parameters
pnumber to be operated
Returns
value of this ^ p (^ is bit-wise XOR operator)
901  {
902  return uint256_t(f, s ^ p);
903  }

◆ operator^() [2/2]

uint256_t uint256_t::operator^ ( const uint256_t p)
inline

operator ^ for uint256_t (bitwise operator)

Parameters
pnumber to be operated
Returns
value of this ^ p (^ is bit-wise XOR operator)
910  {
911  return {this->f ^ p.f, this->s ^ p.s};
912  }

◆ operator^=() [1/2]

template<typename T , typename = typename std::enable_if< std::is_integral<T>::value, T>::type>
uint256_t& uint256_t::operator^= ( const T &  p)
inline

operator ^= for other types (bitwise operator)

Template Parameters
Tintegral type
Parameters
pnumber to be operated
Returns
this = this ^ p (^ is bit-wise XOR operator)
933  {
934  s ^= p;
935  return *this;
936  }

◆ operator^=() [2/2]

uint256_t& uint256_t::operator^= ( const uint256_t p)
inline

operator ^= for uint256_t (bitwise operator)

Parameters
pnumber to be operated
Returns
this = this ^ p (^ is bit-wise XOR operator)
919  {
920  f ^= p.f;
921  s ^= p.s;
922  return *this;
923  }

◆ operator|() [1/2]

template<typename T , typename = typename std::enable_if< std::is_integral<T>::value, T>::type>
uint256_t uint256_t::operator| ( const T &  p)
inline

operator | for other types (bitwise operator)

Template Parameters
Tintegral type
Parameters
pnumber to be operated
Returns
value of this | p (| is bit-wise operator)
856  {
857  return *this | uint256_t(p);
858  }

◆ operator|() [2/2]

uint256_t uint256_t::operator| ( const uint256_t p)
inline

operator | for uint256_t (bitwise operator)

Parameters
pnumber to be operated
Returns
value of this | p (| is bit-wise OR operator)
865  {
866  return {this->f | p.f, this->s | p.s};
867  }

◆ operator|=() [1/2]

template<typename T , typename = typename std::enable_if< std::is_integral<T>::value, T>::type>
uint256_t& uint256_t::operator|= ( const T &  p)
inline

operator |= for other types (bitwise operator)

Template Parameters
Tintegral type
Parameters
pnumber to be operated
Returns
this = this | p (| is bit-wise OR operator)
877  {
878  s |= p;
879  return *this;
880  }

◆ operator|=() [2/2]

uint256_t& uint256_t::operator|= ( const uint256_t p)
inline

operator |= for uint256_t (bitwise operator)

Parameters
pnumber to be operated
Returns
this = this | p (| is bit-wise OR operator)
887  {
888  f |= p.f;
889  s |= p.s;
890  return *this;
891  }

◆ operator||() [1/2]

template<typename T , typename = typename std::enable_if< std::is_integral<T>::value, T>::type>
bool uint256_t::operator|| ( const T &  b)
inline

operator || for other types

Template Parameters
Tintegral type
Parameters
othernumber to be compared with this
Returns
true if this is either one of the values are non-zero, else false
715  {
716  return (s || f) || (b);
717  }

◆ operator||() [2/2]

bool uint256_t::operator|| ( const uint256_t b)
inline

operator || for uint256_t

Parameters
bnumber to be compared with this
Returns
true if one of the values are not zero, else false
612  {
613  return (s || f) || (b.s || b.f);
614  }

◆ operator~()

uint256_t uint256_t::operator~ ( )
inline

operator ~ for uint256_t

Returns
1's complement of this number
723 { return {~f, ~s}; }

◆ upper()

uint128_t uint256_t::upper ( ) const
inline

returns upper 128-bit integer part

Returns
returns upper 128-bit integer part
175 { return f; }

Friends And Related Function Documentation

◆ operator<<

std::ostream& operator<< ( std::ostream op,
uint256_t  p 
)
friend

operator << for printing uint256_t integer

Prints the uint256_t integer in decimal form

Note
Note that this operator is costly since it uses strings to print the value
Parameters
opostream object
p256-bit integer
Returns
op, ostream object.
947  {
948  if (!p.f) {
949  op << p.s;
950  } else {
951  std::string out = "0", p_2 = "1";
952  uint128_t L(1);
953  for (uint64_t i = 0; i < 128; ++i) {
954  if ((p.s & L)) {
955  out = add(out, p_2);
956  }
957  p_2 = add(p_2, p_2);
958  L <<= 1;
959  }
960  L = uint128_t(1);
961  for (int i = 0; i < 128; ++i) {
962  if ((p.f & L)) {
963  out = add(out, p_2);
964  }
965  p_2 = add(p_2, p_2);
966  L <<= 1;
967  }
968  op << out;
969  }
970  return op;
971  }
std::string add(const std::string &first, const std::string &second)
Adding two string.
Definition: uint128_t.hpp:37

The documentation for this class was generated from the following file: