uint128: Check for large shift count before truncating in << and >>

- Correctly handle very large shift counts
- uint128(1) << (uint64_t(1) << 32) should now be 0 as expected
This commit is contained in:
theoretical 2015-01-30 12:54:30 -05:00
parent ac197311ca
commit 4b8c211629

View file

@ -150,15 +150,14 @@ namespace fc
uint128& uint128::operator<<=(const uint128& rhs)
{
unsigned int n = rhs.to_integer();
if(n >= 128)
if(rhs >= 128)
{
hi = 0;
lo = 0;
}
else
{
unsigned int n = rhs.to_integer();
const unsigned int halfsize = 128 / 2;
if(n >= halfsize){
@ -181,17 +180,19 @@ namespace fc
}
}
return *this;
return *this;
}
uint128 & uint128::operator>>=(const uint128& rhs)
{
unsigned int n = rhs.to_integer();
if(n >= 128) {
if(rhs >= 128)
{
hi = 0;
lo = 0;
} else {
}
else
{
unsigned int n = rhs.to_integer();
const unsigned int halfsize = 128 / 2;
if(n >= halfsize) {