diff options
author | chriseth <chris@ethereum.org> | 2018-11-08 18:25:30 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-11-08 18:25:30 +0800 |
commit | cc2de07bc6be6125fb5505d17f8c50fac8d15dc6 (patch) | |
tree | 1e9219c4fd008fd44b529db3cefd7468b6c6db4d /libsolidity | |
parent | bed0368ffac4f9e34ff14e115619ed2cd994e2f7 (diff) | |
parent | e036133d1be1ac87af29ce145052884c2c025ffa (diff) | |
download | dexon-solidity-cc2de07bc6be6125fb5505d17f8c50fac8d15dc6.tar dexon-solidity-cc2de07bc6be6125fb5505d17f8c50fac8d15dc6.tar.gz dexon-solidity-cc2de07bc6be6125fb5505d17f8c50fac8d15dc6.tar.bz2 dexon-solidity-cc2de07bc6be6125fb5505d17f8c50fac8d15dc6.tar.lz dexon-solidity-cc2de07bc6be6125fb5505d17f8c50fac8d15dc6.tar.xz dexon-solidity-cc2de07bc6be6125fb5505d17f8c50fac8d15dc6.tar.zst dexon-solidity-cc2de07bc6be6125fb5505d17f8c50fac8d15dc6.zip |
Merge pull request #5348 from ethereum/boostRationalNegativeDenominatorFix
Fix negative denominator in ``boost::rational`` during exponentiation.
Diffstat (limited to 'libsolidity')
-rw-r--r-- | libsolidity/ast/Types.cpp | 4 | ||||
-rw-r--r-- | libsolidity/ast/Types.h | 9 |
2 files changed, 11 insertions, 2 deletions
diff --git a/libsolidity/ast/Types.cpp b/libsolidity/ast/Types.cpp index d5d11478..6c3863e6 100644 --- a/libsolidity/ast/Types.cpp +++ b/libsolidity/ast/Types.cpp @@ -1144,10 +1144,10 @@ TypePointer RationalNumberType::binaryOperatorResult(Token _operator, TypePointe bigint denominator = optimizedPow(m_value.denominator(), absExp); if (exp >= 0) - value = rational(numerator, denominator); + value = makeRational(numerator, denominator); else // invert - value = rational(denominator, numerator); + value = makeRational(denominator, numerator); } break; } diff --git a/libsolidity/ast/Types.h b/libsolidity/ast/Types.h index b764717f..24ace447 100644 --- a/libsolidity/ast/Types.h +++ b/libsolidity/ast/Types.h @@ -51,6 +51,15 @@ using FunctionTypePointer = std::shared_ptr<FunctionType const>; using TypePointers = std::vector<TypePointer>; using rational = boost::rational<dev::bigint>; +inline rational makeRational(bigint const& _numerator, bigint const& _denominator) +{ + solAssert(_denominator != 0, "division by zero"); + // due to a bug in certain versions of boost the denominator has to be positive + if (_denominator < 0) + return rational(-_numerator, -_denominator); + else + return rational(_numerator, _denominator); +} enum class DataLocation { Storage, CallData, Memory }; |