mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Fix negative denominator in `boost::rational
` during exponentiation.
This commit is contained in:
parent
88aee34c22
commit
e036133d1b
@ -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;
|
||||
}
|
||||
|
@ -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 };
|
||||
|
||||
|
@ -0,0 +1,5 @@
|
||||
contract C {
|
||||
function f() public pure returns (int) {
|
||||
return (-1 / 2) ** -1;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user