Skip to content

Commit

Permalink
Fix negative denominator in boost::rational during exponentiation.
Browse files Browse the repository at this point in the history
  • Loading branch information
ekpyron committed Nov 5, 2018
1 parent 88aee34 commit 1530632
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
9 changes: 7 additions & 2 deletions libsolidity/ast/Types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1145,9 +1145,14 @@ TypePointer RationalNumberType::binaryOperatorResult(Token _operator, TypePointe

if (exp >= 0)
value = rational(numerator, denominator);
else
else {
// invert
value = rational(denominator, numerator);
// due to a bug in certain versions of boost the denominator cannot be negative
if (numerator < 0)
value = rational(-denominator, -numerator);
else
value = rational(denominator, numerator);
}
}
break;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
contract C {
function f() public pure returns (int) {
return (-1 / 2) ** -1;
}
}

0 comments on commit 1530632

Please sign in to comment.