aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorchriseth <c@ethdev.com>2016-05-10 20:07:11 +0800
committerchriseth <c@ethdev.com>2016-05-11 01:40:37 +0800
commitcf226f0607386d1e6d9c75ebc7ce24e733ca4315 (patch)
tree1b608482ef8803a66ed357bd81fd310c04fb69bb
parent02e1c9be0d03f4dd576792dbab7c8f6abca86a5e (diff)
downloaddexon-solidity-cf226f0607386d1e6d9c75ebc7ce24e733ca4315.tar.gz
dexon-solidity-cf226f0607386d1e6d9c75ebc7ce24e733ca4315.tar.zst
dexon-solidity-cf226f0607386d1e6d9c75ebc7ce24e733ca4315.zip
Special case for moving sign bit to fractional part.
-rw-r--r--libsolidity/ast/Types.cpp15
1 files changed, 10 insertions, 5 deletions
diff --git a/libsolidity/ast/Types.cpp b/libsolidity/ast/Types.cpp
index 924ad3b7..31248fb6 100644
--- a/libsolidity/ast/Types.cpp
+++ b/libsolidity/ast/Types.cpp
@@ -767,7 +767,6 @@ shared_ptr<FixedPointType const> RationalNumberType::fixedPointType() const
{
bool negative = (m_value < 0);
unsigned fractionalBits = 0;
- unsigned integerBits = 0;
rational value = abs(m_value); // We care about the sign later.
rational maxValue = negative ?
rational(bigint(1) << 255):
@@ -788,13 +787,19 @@ shared_ptr<FixedPointType const> RationalNumberType::fixedPointType() const
// modify value to satisfy bit requirements for negative numbers:
// add one bit for sign and decrement because negative numbers can be larger
v = (v - 1) << 1;
-
+
if (v > u256(-1))
return shared_ptr<FixedPointType const>();
- if (0 == integerPart())
+
+ unsigned totalBits = bytesRequired(v) * 8;
+ solAssert(totalBits <= 256, "");
+ unsigned integerBits = totalBits >= fractionalBits ? totalBits - fractionalBits : 0;
+ // Special case: Numbers between -1 and 0 have their sign bit in the fractional part.
+ if (negative && abs(m_value) < 1 && totalBits > fractionalBits)
+ {
+ fractionalBits += 8;
integerBits = 0;
- else
- integerBits = (bytesRequired(v) * 8) - fractionalBits;
+ }
if (integerBits > 256 || fractionalBits > 256 || fractionalBits + integerBits > 256)
return shared_ptr<FixedPointType const>();