From 5fb0bcce4532e9dec8a5aa0ef056d5a1c12405a2 Mon Sep 17 00:00:00 2001 From: chriseth Date: Wed, 12 Oct 2016 17:28:47 +0200 Subject: Replace `fixed` by standard `encode` function. This way, we can use ``` BOOST_CHECK(callContractFunction("t(fixed8x128)", make_pair(rational(2, 3), 128)) == encodeArgs(u256(9))); ``` which is a bit more self-explanatory, I would say. --- test/libsolidity/SolidityExecutionFramework.h | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) (limited to 'test') diff --git a/test/libsolidity/SolidityExecutionFramework.h b/test/libsolidity/SolidityExecutionFramework.h index a4181dfe..bfd87c2b 100644 --- a/test/libsolidity/SolidityExecutionFramework.h +++ b/test/libsolidity/SolidityExecutionFramework.h @@ -156,6 +156,14 @@ public: static bytes encode(char const* _value) { return encode(std::string(_value)); } static bytes encode(byte _value) { return bytes(31, 0) + bytes{_value}; } static bytes encode(u256 const& _value) { return toBigEndian(_value); } + /// @returns the fixed-point encoding of a rational number with a given + /// number of fractional bits. + static bytes encode(std::pair const& _valueAndPrecision) + { + rational const& value = _valueAndPrecision.first; + int fractionalBits = _valueAndPrecision.second; + return encode(u256((value.numerator() << fractionalBits) / value.denominator())); + } static bytes encode(h256 const& _value) { return _value.asBytes(); } static bytes encode(bytes const& _value, bool _padLeft = true) { @@ -187,12 +195,6 @@ public: { return encodeArgs(u256(0x20), u256(_arg.size()), _arg); } - static u256 fixed(dev::bigint _numerator, dev::bigint _denominator, int _fixedBits) - { - rational _value = rational(dev::bigint(_numerator), dev::bigint(_denominator)); - rational value = _value * boost::multiprecision::pow(bigint(2), _fixedBits); - return u256(value.numerator()/value.denominator()); - } class ContractInterface { public: -- cgit