diff options
author | Daniel Kirchner <daniel@ekpyron.org> | 2018-06-12 23:19:20 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-06-12 23:19:20 +0800 |
commit | e2f4a9fcf409df1108d355824de12ff43682a728 (patch) | |
tree | 0e1be338e5347370ebca2075b164b56bc61046dd /libsolidity | |
parent | 2c8eca5dcfc5f961615eb1673f150d3088954a46 (diff) | |
parent | 510f227bd78cda33181531141c88c6b948d72935 (diff) | |
download | dexon-solidity-e2f4a9fcf409df1108d355824de12ff43682a728.tar dexon-solidity-e2f4a9fcf409df1108d355824de12ff43682a728.tar.gz dexon-solidity-e2f4a9fcf409df1108d355824de12ff43682a728.tar.bz2 dexon-solidity-e2f4a9fcf409df1108d355824de12ff43682a728.tar.lz dexon-solidity-e2f4a9fcf409df1108d355824de12ff43682a728.tar.xz dexon-solidity-e2f4a9fcf409df1108d355824de12ff43682a728.tar.zst dexon-solidity-e2f4a9fcf409df1108d355824de12ff43682a728.zip |
Merge pull request #4277 from ethereum/signedRightShift
Signed Right Shift: Additional test and more explanation.
Diffstat (limited to 'libsolidity')
-rw-r--r-- | libsolidity/ast/Types.cpp | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/libsolidity/ast/Types.cpp b/libsolidity/ast/Types.cpp index 94e04b6a..c4d97c64 100644 --- a/libsolidity/ast/Types.cpp +++ b/libsolidity/ast/Types.cpp @@ -1088,8 +1088,13 @@ TypePointer RationalNumberType::binaryOperatorResult(Token::Value _operator, Typ else { 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 + // Add 1 to the negative value before dividing to get a result that is strictly too large, + // then subtract 1 afterwards to round towards negative infinity. + // This is the same algorithm as used in ExpressionCompiler::appendShiftOperatorCode(...). + // To see this note that for negative x, xor(x,all_ones) = (-x-1) and + // therefore xor(div(xor(x,all_ones), exp(2, shift_amount)), all_ones) is + // -(-x - 1) / 2^shift_amount - 1, which is the same as + // (x + 1) / 2^shift_amount - 1. 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); |