Type checks and integer shift checked

This commit is contained in:
Ashish Bhanu Daulatabad 2021-04-11 00:05:40 +05:30
parent 6c4fdc53d1
commit 276fde9d3f
2 changed files with 13 additions and 13 deletions

View File

@ -637,19 +637,20 @@ class uint128_t {
uint128_t operator<<(const T p) {
if (!p) {
return uint128_t(f, s);
}
if (p >= 64 && p <= 128) {
} else if (p >= 64 && p <= 128) {
return uint128_t((this->s << (p - 64)), 0);
}
} else if (p < 64 && p > 0) {
return uint128_t((this->f << p) + ((this->s >> (64 - p))),
this->s << p);
}
return uint128_t(0);
}
template <typename T, typename = typename std::enable_if<
std::is_integral<T>::value, T>::type>
uint128_t &operator<<=(const T p) {
if (p) {
if (p >= 64) {
if (p >= 64 && p <= 128) {
this->f = (this->s << (p - 64));
this->s = 0;
} else {
@ -665,13 +666,14 @@ class uint128_t {
uint128_t operator>>(const T p) {
if (!p) {
return uint128_t(this->f, this->s);
}
if (p >= 64) {
} else if (p >= 64 && p <= 128) {
return uint128_t(0, (this->f >> (p - 64)));
}
} else if (p < 64 && p > 0) {
return uint128_t((this->f >> p),
(this->s >> p) + (this->f << (64 - p)));
}
return uint128_t(0);
}
template <typename T, typename = typename std::enable_if<
std::is_integral<T>::value, T>::type>

View File

@ -597,8 +597,7 @@ class uint256_t {
uint256_t operator<<(const T &p) {
if (!p) {
return uint256_t(this->f, this->s);
}
if (p >= 128) {
} else if (p >= 128) {
return uint256_t((this->s << (p - 128)), uint128_t(0));
}
return uint256_t((this->f << p) + (this->s >> (128 - p)),
@ -625,8 +624,7 @@ class uint256_t {
uint256_t operator>>(const T &p) {
if (!p) {
return uint256_t(this->f, this->s);
}
if (p >= 128) {
} else if (p >= 128) {
return uint256_t(uint128_t(0), (this->f >> (p - 128)));
}
return uint256_t((this->f >> p),