25 #include <boost/multiprecision/cpp_int.hpp>
33 using boost::multiprecision::uint256_t;
35 static fc::uint128_t to_capped_128(
const uint256_t& t )
37 if( t >= std::numeric_limits<fc::uint128_t>::max() )
38 return std::numeric_limits<fc::uint128_t>::max();
39 return static_cast<fc::uint128_t
>(t);
45 if( precision == 0 || amount == fc::uint128_t() )
49 uint8_t pos = s.find_last_not_of(
'0' );
50 uint8_t len = s.size();
53 uint8_t left_len = len - precision;
54 ss << s.substr( 0, left_len );
56 ss <<
'.' << s.substr( left_len, pos - left_len + 1 );
61 for( uint8_t i = precision - len; i > 0; --i )
63 ss << s.substr( 0, pos + 1 );
69 const uint8_t base_precision,
70 const uint8_t quote_precision )
81 new_price.
base.
amount = std::numeric_limits<int64_t>::max();
86 fc::uint128_t price128 = fc::uint128_t( new_price.
base.
amount.
value ) * uint64_t(10000000000000000000ULL)
117 old_price1.
quote.
amount = std::numeric_limits<int64_t>::max();
121 old_price1.
base.
amount = std::numeric_limits<int64_t>::max();
128 new_price1.
quote.
amount = std::numeric_limits<int64_t>::max();
132 new_price1.
base.
amount = std::numeric_limits<int64_t>::max();
141 bool non_negative = (new256 >= old256);
144 diff256 = new256 - old256;
146 diff256 = old256 - new256;
147 diff256 = diff256 * 10000 / old256;
149 if( non_negative || diff_str ==
"0" )
152 return "-" + diff_str;