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:
		
							parent
							
								
									f67bfd24a3
								
							
						
					
					
						commit
						f0ea817580
					
				| @ -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) | ||||
| 		{ | ||||
|  | ||||
| @ -3441,278 +3441,6 @@ BOOST_AUTO_TEST_CASE(inline_array_fixed_rationals) | ||||
| 	BOOST_CHECK(success(text)); | ||||
| } | ||||
| 
 | ||||
| BOOST_AUTO_TEST_CASE(size_capabilities_of_fixed_point_types) | ||||
| { | ||||
| 	char const* text = R"( | ||||
| 		contract test { | ||||
| 			function f() { | ||||
| 				ufixed0x64 a = 0.12345678; | ||||
| 				ufixed8x0 b = 12345678.0; | ||||
| 				ufixed0x64 c = 0.00000009; | ||||
| 			} | ||||
| 		} | ||||
| 	)"; | ||||
| 	BOOST_CHECK(success(text)); | ||||
| } | ||||
| 
 | ||||
| BOOST_AUTO_TEST_CASE(var_capable_of_holding_constant_rationals) | ||||
| { | ||||
| 	char const* text = R"( | ||||
| 		contract test { | ||||
| 			function f() { | ||||
| 				var a = 0.12345678; | ||||
| 				var b = 12345678.0; | ||||
| 				var c = 0.00000009; | ||||
| 			} | ||||
| 		} | ||||
| 	)"; | ||||
| 	BOOST_CHECK(success(text)); | ||||
| } | ||||
| 
 | ||||
| BOOST_AUTO_TEST_CASE(invalid_rational_exponent_usage) | ||||
| { | ||||
| 	char const* text = R"( | ||||
| 		contract test { | ||||
| 			function f() { | ||||
| 				fixed8x8 a = 3 ** 1.5; | ||||
| 				fixed24x24 b = 2 ** (1/2); | ||||
| 				fixed40x40 c = 42 ** (-1/4); | ||||
| 				fixed48x48 d = 16 ** -0.33; | ||||
| 			} | ||||
| 		} | ||||
| 	)"; | ||||
| 	BOOST_CHECK(!success(text)); | ||||
| } | ||||
| 
 | ||||
| BOOST_AUTO_TEST_CASE(fixed_point_casting_exponents) | ||||
| { | ||||
| 	char const* text = R"( | ||||
| 		contract test { | ||||
| 			function f() { | ||||
| 				fixed a = 3 ** fixed(1.5); | ||||
| 				fixed b = 2 ** fixed(1/2); | ||||
| 				fixed c = 42 ** fixed(-1/4); | ||||
| 				fixed d = 16 ** fixed(-0.33); | ||||
| 			} | ||||
| 		} | ||||
| 	)"; | ||||
| 	BOOST_CHECK(success(text)); | ||||
| } | ||||
| 
 | ||||
| BOOST_AUTO_TEST_CASE(rational_unary_operation) | ||||
| { | ||||
| 	char const* text = R"( | ||||
| 		contract test { | ||||
| 			function f() { | ||||
| 				fixed a = +3.5134; | ||||
| 				fixed b = -2.5145; | ||||
| 			} | ||||
| 		} | ||||
| 	)"; | ||||
| 	BOOST_CHECK(success(text)); | ||||
| } | ||||
| 
 | ||||
| BOOST_AUTO_TEST_CASE(rational_bitnot_unary_operation) | ||||
| { | ||||
| 	char const* text = R"( | ||||
| 		contract test { | ||||
| 			function f() { | ||||
| 				fixed a = ~3.56; | ||||
| 			} | ||||
| 		} | ||||
| 	)"; | ||||
| 	BOOST_CHECK(!success(text)); | ||||
| } | ||||
| 
 | ||||
| BOOST_AUTO_TEST_CASE(rational_bitor_binary_operation) | ||||
| { | ||||
| 	char const* text = R"( | ||||
| 		contract test { | ||||
| 			function f() { | ||||
| 				fixed a = 1.56 | 3; | ||||
| 			} | ||||
| 		} | ||||
| 	)"; | ||||
| 	BOOST_CHECK(!success(text)); | ||||
| } | ||||
| 
 | ||||
| BOOST_AUTO_TEST_CASE(rational_bitxor_binary_operation) | ||||
| { | ||||
| 	char const* text = R"( | ||||
| 		contract test { | ||||
| 			function f() { | ||||
| 				fixed a = 1.56 ^ 3; | ||||
| 			} | ||||
| 		} | ||||
| 	)"; | ||||
| 	BOOST_CHECK(!success(text)); | ||||
| } | ||||
| 
 | ||||
| BOOST_AUTO_TEST_CASE(rational_bitand_binary_operation) | ||||
| { | ||||
| 	char const* text = R"( | ||||
| 		contract test { | ||||
| 			function f() { | ||||
| 				fixed a = 1.56 & 3; | ||||
| 			} | ||||
| 		} | ||||
| 	)"; | ||||
| 
 | ||||
| 	BOOST_CHECK(success(text)); | ||||
| } | ||||
| 
 | ||||
| BOOST_AUTO_TEST_CASE(valid_fraction_fixed_type) | ||||
| { | ||||
| 	char const* text = R"( | ||||
| 		contract test { | ||||
| 			function f(){ | ||||
| 				fixed8x8 a = (2**24)/127; | ||||
| 				fixed0x8 b = 1/256; | ||||
| 			} | ||||
| 		} | ||||
| 	)"; | ||||
| 
 | ||||
| 	BOOST_CHECK(success(text)); | ||||
| } | ||||
| 
 | ||||
| BOOST_AUTO_TEST_CASE(valid_fixed_types) | ||||
| { | ||||
| 	char const* text = R"( | ||||
| 		contract test { | ||||
| 			function f(){ | ||||
| 				fixed8x8 a = 87654321.12345678; | ||||
| 				fixed16x16 b = a**2; | ||||
| 				fixed24x24 c = b**3; | ||||
| 				fixed32x32 d = b**2; | ||||
| 				fixed40x40 e = a**5; | ||||
| 			} | ||||
| 		} | ||||
| 	)"; | ||||
| 
 | ||||
| 	BOOST_CHECK(success(text)); | ||||
| } | ||||
| 
 | ||||
| BOOST_AUTO_TEST_CASE(fixed_type_int_conversion) | ||||
| { | ||||
| 	char const* text = R"( | ||||
| 		contract test { | ||||
| 			function f() { | ||||
| 				uint128 a = 3; | ||||
| 				int128 b = 4; | ||||
| 				fixed c = b; | ||||
| 				ufixed d = a; | ||||
| 			} | ||||
| 		} | ||||
| 	)"; | ||||
| 	BOOST_CHECK(success(text)); | ||||
| } | ||||
| 
 | ||||
| BOOST_AUTO_TEST_CASE(fixed_type_const_int_conversion) | ||||
| { | ||||
| 	char const* text = R"( | ||||
| 		contract test { | ||||
| 			function f() { | ||||
| 				fixed c = 3; | ||||
| 				ufixed d = 4; | ||||
| 			} | ||||
| 		} | ||||
| 	)"; | ||||
| 	BOOST_CHECK(success(text)); | ||||
| } | ||||
| 
 | ||||
| BOOST_AUTO_TEST_CASE(fixed_type_literal) | ||||
| { | ||||
| 	char const* text = R"( | ||||
| 		contract test { | ||||
| 			function f() { | ||||
| 				fixed a = 3.14; | ||||
| 				ufixed d = 2.555555; | ||||
| 			} | ||||
| 		} | ||||
| 	)"; | ||||
| 	BOOST_CHECK(success(text)); | ||||
| } | ||||
| 
 | ||||
| BOOST_AUTO_TEST_CASE(fixed_type_literal_expression) | ||||
| { | ||||
| 	char const* text = R"( | ||||
| 		contract test { | ||||
| 			function f() { | ||||
| 				fixed a = 3.14 * 3; | ||||
| 				ufixed b = 4 - 2.555555; | ||||
| 				fixed c = 1.0 / 3.0; | ||||
| 				ufixed d = 599 + .5367; | ||||
| 				ufixed e = 35.245 % 12.9; | ||||
| 				ufixed f = 1.2 % 2.00000; | ||||
| 				fixed g = 2 ** -2; | ||||
| 			} | ||||
| 		} | ||||
| 	)"; | ||||
| 	BOOST_CHECK(success(text)); | ||||
| } | ||||
| 
 | ||||
| BOOST_AUTO_TEST_CASE(uint_array_declaration_with_fixed_type) | ||||
| { | ||||
| 	char const* text = R"( | ||||
| 		contract test { | ||||
| 			function f() { | ||||
| 				uint[fixed(3.56)] a; | ||||
| 			} | ||||
| 		} | ||||
| 	)"; | ||||
| 	BOOST_CHECK(!success(text)); | ||||
| } | ||||
| 
 | ||||
| 
 | ||||
| BOOST_AUTO_TEST_CASE(array_declaration_with_rational) | ||||
| { | ||||
| 	char const* text = R"( | ||||
| 		contract test { | ||||
| 			function f() { | ||||
| 				uint[3.56] a; | ||||
| 			} | ||||
| 		} | ||||
| 	)"; | ||||
| 	BOOST_CHECK(!success(text)); | ||||
| } | ||||
| 
 | ||||
| BOOST_AUTO_TEST_CASE(mapping_with_fixed_literal) | ||||
| { | ||||
| 	char const* text = R"( | ||||
| 		contract test { | ||||
| 			mapping(fixed => string) fixedString; | ||||
| 			function f() { | ||||
| 				fixedString[3.14] = "Pi"; | ||||
| 			} | ||||
| 		} | ||||
| 	)"; | ||||
| 	BOOST_CHECK(success(text)); | ||||
| } | ||||
| 
 | ||||
| BOOST_AUTO_TEST_CASE(inline_array_fixed_type) | ||||
| { | ||||
| 	char const* text = R"( | ||||
| 		contract test { | ||||
| 			function f() { | ||||
| 				fixed[3] memory a = [fixed(3.5), fixed(4.1234), fixed(967.32)]; | ||||
| 			} | ||||
| 		} | ||||
| 	)"; | ||||
| 	BOOST_CHECK(success(text)); | ||||
| } | ||||
| 
 | ||||
| BOOST_AUTO_TEST_CASE(inline_array_fixed_literals) | ||||
| { | ||||
| 	char const* text = R"( | ||||
| 		contract test { | ||||
| 			function f() { | ||||
| 				ufixed8x16[3] memory a = [3.5, 4.1234, 2.5]; | ||||
| 			} | ||||
| 		} | ||||
| 	)"; | ||||
| 	BOOST_CHECK(success(text)); | ||||
| } | ||||
| 
 | ||||
| BOOST_AUTO_TEST_CASE(zero_and_eight_variants_fixed) | ||||
| { | ||||
| 	char const* text = R"( | ||||
|  | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user