diff options
author | chriseth <chris@ethereum.org> | 2016-10-20 20:20:58 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-10-20 20:20:58 +0800 |
commit | 9d30450167d5b262d0e7379f44f01637715fb878 (patch) | |
tree | 72c4f401a72a54c81c78b53870fc04483dc235e4 /libsolidity | |
parent | 2bb37f8203d5b64f603d4c7c802407a5500429b5 (diff) | |
parent | d5c94cb4121f2ab97ea52a5471e18c26434dd6e3 (diff) | |
download | dexon-solidity-9d30450167d5b262d0e7379f44f01637715fb878.tar.gz dexon-solidity-9d30450167d5b262d0e7379f44f01637715fb878.tar.zst dexon-solidity-9d30450167d5b262d0e7379f44f01637715fb878.zip |
Merge pull request #1034 from ethereum/shift-constants
Shift constants (<< and >>)
Diffstat (limited to 'libsolidity')
-rw-r--r-- | libsolidity/ast/Types.cpp | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/libsolidity/ast/Types.cpp b/libsolidity/ast/Types.cpp index 068cc138..eb98047c 100644 --- a/libsolidity/ast/Types.cpp +++ b/libsolidity/ast/Types.cpp @@ -705,6 +705,34 @@ TypePointer RationalNumberType::binaryOperatorResult(Token::Value _operator, Typ value = rational(denominator, numerator); break; } + case Token::SHL: + { + using boost::multiprecision::pow; + if (fractional) + return TypePointer(); + else if (other.m_value < 0) + return TypePointer(); + else if (other.m_value > numeric_limits<uint32_t>::max()) + return TypePointer(); + uint32_t exponent = other.m_value.numerator().convert_to<uint32_t>(); + value = m_value.numerator() * pow(bigint(2), exponent); + break; + } + // NOTE: we're using >> (SAR) to denote right shifting. The type of the LValue + // determines the resulting type and the type of shift (SAR or SHR). + case Token::SAR: + { + using boost::multiprecision::pow; + if (fractional) + return TypePointer(); + else if (other.m_value < 0) + return TypePointer(); + else if (other.m_value > numeric_limits<uint32_t>::max()) + return TypePointer(); + uint32_t exponent = other.m_value.numerator().convert_to<uint32_t>(); + value = rational(m_value.numerator() / pow(bigint(2), exponent), 1); + break; + } default: return TypePointer(); } |