fixing modulus and Solidity Name and Type Resolution

minor fixes

current attempts at binary fixup
This commit is contained in:
VoR0220
2016-05-09 11:41:03 -05:00
parent f67bfd24a3
commit f0ea817580
4 changed files with 10 additions and 284 deletions
+8 -10
View File
@@ -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);
}
+1 -1
View File
@@ -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(); }
+1 -1
View File
@@ -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)
{