diff options
author | VoR0220 <catalanor0220@gmail.com> | 2016-03-30 05:13:00 +0800 |
---|---|---|
committer | VoR0220 <catalanor0220@gmail.com> | 2016-05-10 00:41:03 +0800 |
commit | f0ea817580d7f8d5c5177adf1a2e39e5e560fefc (patch) | |
tree | 7b32f9016b79ba31c75942cc7653cb4335ec6c54 /libsolidity/ast | |
parent | f67bfd24a3c294f0388f847be213a5236ffd60a4 (diff) | |
download | dexon-solidity-f0ea817580d7f8d5c5177adf1a2e39e5e560fefc.tar.gz dexon-solidity-f0ea817580d7f8d5c5177adf1a2e39e5e560fefc.tar.zst dexon-solidity-f0ea817580d7f8d5c5177adf1a2e39e5e560fefc.zip |
fixing modulus and Solidity Name and Type Resolution
minor fixes
current attempts at binary fixup
Diffstat (limited to 'libsolidity/ast')
-rw-r--r-- | libsolidity/ast/Types.cpp | 18 | ||||
-rw-r--r-- | libsolidity/ast/Types.h | 2 |
2 files changed, 9 insertions, 11 deletions
diff --git a/libsolidity/ast/Types.cpp b/libsolidity/ast/Types.cpp index 4c3947df..8c0d21b1 100644 --- a/libsolidity/ast/Types.cpp +++ b/libsolidity/ast/Types.cpp @@ -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); } diff --git a/libsolidity/ast/Types.h b/libsolidity/ast/Types.h index ef0a69b3..84236762 100644 --- a/libsolidity/ast/Types.h +++ b/libsolidity/ast/Types.h @@ -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(); } |