mirror of
https://hub.njuu.cf/TheAlgorithms/C-Plus-Plus.git
synced 2023-10-11 13:05:55 +08:00
Type checks and integer shift checked
This commit is contained in:
parent
6c4fdc53d1
commit
276fde9d3f
@ -637,19 +637,20 @@ class uint128_t {
|
|||||||
uint128_t operator<<(const T p) {
|
uint128_t operator<<(const T p) {
|
||||||
if (!p) {
|
if (!p) {
|
||||||
return uint128_t(f, s);
|
return uint128_t(f, s);
|
||||||
}
|
} else if (p >= 64 && p <= 128) {
|
||||||
if (p >= 64 && p <= 128) {
|
|
||||||
return uint128_t((this->s << (p - 64)), 0);
|
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((this->f << p) + ((this->s >> (64 - p))),
|
return uint128_t(0);
|
||||||
this->s << p);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T, typename = typename std::enable_if<
|
template <typename T, typename = typename std::enable_if<
|
||||||
std::is_integral<T>::value, T>::type>
|
std::is_integral<T>::value, T>::type>
|
||||||
uint128_t &operator<<=(const T p) {
|
uint128_t &operator<<=(const T p) {
|
||||||
if (p) {
|
if (p) {
|
||||||
if (p >= 64) {
|
if (p >= 64 && p <= 128) {
|
||||||
this->f = (this->s << (p - 64));
|
this->f = (this->s << (p - 64));
|
||||||
this->s = 0;
|
this->s = 0;
|
||||||
} else {
|
} else {
|
||||||
@ -665,12 +666,13 @@ class uint128_t {
|
|||||||
uint128_t operator>>(const T p) {
|
uint128_t operator>>(const T p) {
|
||||||
if (!p) {
|
if (!p) {
|
||||||
return uint128_t(this->f, this->s);
|
return uint128_t(this->f, this->s);
|
||||||
}
|
} else if (p >= 64 && p <= 128) {
|
||||||
if (p >= 64) {
|
|
||||||
return uint128_t(0, (this->f >> (p - 64)));
|
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((this->f >> p),
|
return uint128_t(0);
|
||||||
(this->s >> p) + (this->f << (64 - p)));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T, typename = typename std::enable_if<
|
template <typename T, typename = typename std::enable_if<
|
||||||
|
@ -597,8 +597,7 @@ class uint256_t {
|
|||||||
uint256_t operator<<(const T &p) {
|
uint256_t operator<<(const T &p) {
|
||||||
if (!p) {
|
if (!p) {
|
||||||
return uint256_t(this->f, this->s);
|
return uint256_t(this->f, this->s);
|
||||||
}
|
} else if (p >= 128) {
|
||||||
if (p >= 128) {
|
|
||||||
return uint256_t((this->s << (p - 128)), uint128_t(0));
|
return uint256_t((this->s << (p - 128)), uint128_t(0));
|
||||||
}
|
}
|
||||||
return uint256_t((this->f << p) + (this->s >> (128 - p)),
|
return uint256_t((this->f << p) + (this->s >> (128 - p)),
|
||||||
@ -625,8 +624,7 @@ class uint256_t {
|
|||||||
uint256_t operator>>(const T &p) {
|
uint256_t operator>>(const T &p) {
|
||||||
if (!p) {
|
if (!p) {
|
||||||
return uint256_t(this->f, this->s);
|
return uint256_t(this->f, this->s);
|
||||||
}
|
} else if (p >= 128) {
|
||||||
if (p >= 128) {
|
|
||||||
return uint256_t(uint128_t(0), (this->f >> (p - 128)));
|
return uint256_t(uint128_t(0), (this->f >> (p - 128)));
|
||||||
}
|
}
|
||||||
return uint256_t((this->f >> p),
|
return uint256_t((this->f >> p),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user