mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Special case for moving sign bit to fractional part.
This commit is contained in:
parent
02e1c9be0d
commit
cf226f0607
@ -767,7 +767,6 @@ shared_ptr<FixedPointType const> RationalNumberType::fixedPointType() const
|
|||||||
{
|
{
|
||||||
bool negative = (m_value < 0);
|
bool negative = (m_value < 0);
|
||||||
unsigned fractionalBits = 0;
|
unsigned fractionalBits = 0;
|
||||||
unsigned integerBits = 0;
|
|
||||||
rational value = abs(m_value); // We care about the sign later.
|
rational value = abs(m_value); // We care about the sign later.
|
||||||
rational maxValue = negative ?
|
rational maxValue = negative ?
|
||||||
rational(bigint(1) << 255):
|
rational(bigint(1) << 255):
|
||||||
@ -791,10 +790,16 @@ shared_ptr<FixedPointType const> RationalNumberType::fixedPointType() const
|
|||||||
|
|
||||||
if (v > u256(-1))
|
if (v > u256(-1))
|
||||||
return shared_ptr<FixedPointType const>();
|
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;
|
integerBits = 0;
|
||||||
else
|
}
|
||||||
integerBits = (bytesRequired(v) * 8) - fractionalBits;
|
|
||||||
|
|
||||||
if (integerBits > 256 || fractionalBits > 256 || fractionalBits + integerBits > 256)
|
if (integerBits > 256 || fractionalBits > 256 || fractionalBits + integerBits > 256)
|
||||||
return shared_ptr<FixedPointType const>();
|
return shared_ptr<FixedPointType const>();
|
||||||
|
Loading…
Reference in New Issue
Block a user