mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
fixing modulus and Solidity Name and Type Resolution
minor fixes current attempts at binary fixup
This commit is contained in:
@@ -713,8 +713,9 @@ TypePointer RationalNumberType::binaryOperatorResult(Token::Value _operator, Typ
|
||||
else if (fixedPointType)
|
||||
{
|
||||
value = m_value;
|
||||
bigint integers = m_value.numerator() / m_value.denominator();
|
||||
value -= integers;
|
||||
rational divisor = m_value / other.m_value;
|
||||
value -= divisor * m_value;
|
||||
cout << "MODULO VALUE: " << value << endl;
|
||||
}
|
||||
else
|
||||
value = m_value.numerator() % other.m_value.numerator();
|
||||
@@ -816,7 +817,7 @@ shared_ptr<FixedPointType const> RationalNumberType::fixedPointType() const
|
||||
bool fractionalSignBit = integers == 0; //sign the fractional side or the integer side
|
||||
bool negative = (m_value < 0);
|
||||
//todo: change name
|
||||
bigint fractionalBits = fractionalBitsNeeded();
|
||||
bigint fractionalBits = findFractionNumberAndBits();
|
||||
cout << "Total int: " << fractionalBits.str() << endl;
|
||||
if (negative && !fractionalSignBit) // convert to positive number of same bit requirements
|
||||
{
|
||||
@@ -844,23 +845,20 @@ shared_ptr<FixedPointType const> RationalNumberType::fixedPointType() const
|
||||
}
|
||||
|
||||
//todo: change name of function
|
||||
bigint RationalNumberType::findFractionNumberAndBits(bool getWholeNumber = false) const
|
||||
tuple<bigint, unsigned> RationalNumberType::findFractionNumberAndBits(bool getWholeNumber) const
|
||||
{
|
||||
rational value;
|
||||
if (getWholeNumber)
|
||||
value = m_value;
|
||||
else
|
||||
value = m_value - wholeNumbers();
|
||||
for (unsigned fractionalBits = 0; value < boost::multiprecision::pow(bigint(2), 256); fractionalBits += 8, value *= 256)
|
||||
for (unsigned fractionalBits = 0; value < boost::multiprecision::pow(bigint(2), 256); fractionalBits += 8, value *= 10)
|
||||
{
|
||||
if (value.denominator() == 1)
|
||||
return value.numerator()/value.denominator();
|
||||
for ( ; value.denominator() != 1 && value < boost::multiprecision::pow(bigint(2), fractionalBits); value *= 10)
|
||||
if (value.denominator() == 1)
|
||||
return value.numerator()/value.denominator();
|
||||
return make_tuple(value.numerator(), fractionalBits);
|
||||
}
|
||||
cout << "too big :(" << endl;
|
||||
return value.numerator()/value.denominator();
|
||||
return make_tuple(value.numerator()/value.denominator(), fractionalBits);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -388,7 +388,7 @@ public:
|
||||
/// @returns the smallest fixed type that can hold the value or an empty pointer
|
||||
std::shared_ptr<FixedPointType const> fixedPointType() const;
|
||||
|
||||
bigint fractionalBitsNeeded() const;
|
||||
std::tuple<bigint, unsigned> findFractionNumberAndBits(bool getWholeNumber = false) const;
|
||||
bigint denominator() const { return m_value.denominator(); }
|
||||
bigint wholeNumbers() const { return m_value.numerator() / m_value.denominator(); }
|
||||
|
||||
|
||||
@@ -345,7 +345,7 @@ void CompilerUtils::convertType(Type const& _typeOnStack, Type const& _targetTyp
|
||||
break;
|
||||
case Type::Category::Integer:
|
||||
case Type::Category::Contract:
|
||||
case Type::Category::RationalNumber
|
||||
case Type::Category::RationalNumber:
|
||||
case Type::Category::FixedPoint:
|
||||
if (targetTypeCategory == Type::Category::FixedBytes)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user