mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Use proper SAR for signed right shifts and emulate on pre-constantinople.
This commit is contained in:
committed by
Alex Beregszaszi
parent
8999a2f375
commit
f33dc92cbd
@@ -1084,9 +1084,16 @@ TypePointer RationalNumberType::binaryOperatorResult(Token::Value _operator, Typ
|
||||
{
|
||||
uint32_t exponent = other.m_value.numerator().convert_to<uint32_t>();
|
||||
if (exponent > mostSignificantBit(boost::multiprecision::abs(m_value.numerator())))
|
||||
value = 0;
|
||||
value = m_value.numerator() < 0 ? -1 : 0;
|
||||
else
|
||||
value = rational(m_value.numerator() / boost::multiprecision::pow(bigint(2), exponent), 1);
|
||||
{
|
||||
if (m_value.numerator() < 0)
|
||||
// add 1 to the negative value before dividing to get a result that is strictly too large
|
||||
// subtract 1 afterwards to round towards negative infinity
|
||||
value = rational((m_value.numerator() + 1) / boost::multiprecision::pow(bigint(2), exponent) - bigint(1), 1);
|
||||
else
|
||||
value = rational(m_value.numerator() / boost::multiprecision::pow(bigint(2), exponent), 1);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user