Skip to content

Commit

Permalink
update uint256_t with calccrypto/uint128_t#17 fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
calccrypto committed Mar 22, 2021
1 parent f6ac404 commit a6092b5
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 0 deletions.
10 changes: 10 additions & 0 deletions uint128_t.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ uint128_t::uint128_t(const char *s) {
init(s);
}

uint128_t::uint128_t(const bool & b)
: uint128_t((uint8_t) b)
{}

void uint128_t::init(const char *s) {
if (s == NULL || s[0] == 0) { uint128_t(); return; }
if (s[1] == 'x')
Expand Down Expand Up @@ -49,6 +53,12 @@ uint8_t uint128_t::HexToInt(const char *s) const {
return ret;
}

uint128_t & uint128_t::operator=(const bool & rhs) {
UPPER = 0;
LOWER = rhs;
return *this;
}

uint128_t::operator bool() const{
return (bool) (UPPER | LOWER);
}
Expand Down
3 changes: 3 additions & 0 deletions uint128_t.include
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ class uint128_t{
uint128_t(uint128_t && rhs) = default;
uint128_t(std::string & s);
uint128_t(const char *s);
uint128_t(const bool & b);

template <typename T, typename = typename std::enable_if<std::is_integral<T>::value, T>::type >
uint128_t(const T & rhs)
Expand Down Expand Up @@ -116,6 +117,8 @@ class uint128_t{
return *this;
}

uint128_t & operator=(const bool & rhs);

// Typecast Operators
operator bool() const;
operator uint8_t() const;
Expand Down
10 changes: 10 additions & 0 deletions uint256_t.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ uint256_t::uint256_t(const char * s, uint8_t base) {
init_from_base(s, base);
}

uint256_t::uint256_t(const bool & b)
: uint256_t((uint8_t) b)
{}

void uint256_t::init(const char * s) {
//create from string
char buffer[64];
Expand Down Expand Up @@ -66,6 +70,12 @@ void uint256_t::init_from_base(const char * s, uint8_t base) {
}
}

uint256_t & uint256_t::operator=(const bool & rhs) {
UPPER = 0;
LOWER = rhs;
return *this;
}

uint256_t::operator bool() const{
return (bool) (UPPER | LOWER);
}
Expand Down
3 changes: 3 additions & 0 deletions uint256_t.include
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ class uint256_t{
uint256_t(const char *val);
uint256_t(const std::string & s, uint8_t base);
uint256_t(const char *val, uint8_t base);
uint256_t(const bool & b);

template <typename T, typename = typename std::enable_if<std::is_integral<T>::value, T>::type >
uint256_t(const T & rhs)
Expand Down Expand Up @@ -144,6 +145,8 @@ class uint256_t{
return *this;
}

uint256_t & operator=(const bool & rhs);

// Typecast Operators
operator bool () const;
operator uint8_t () const;
Expand Down

0 comments on commit a6092b5

Please sign in to comment.