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;
std::string price_to_string(const graphene::protocol::price &_price, const uint8_t base_precision, const uint8_t quote_precision)
std::string uint128_amount_to_string(const fc::uint128_t &amount, const uint8_t precision)
The price struct stores asset prices in the BitShares system.
#define FC_CAPTURE_AND_RETHROW(...)
#define FC_ASSERT(TEST,...)
Checks a condition and throws an assert_exception if the test is FALSE.
stores null, int64, uint64, double, bool, string, std::vector<variant>, and variant_object's.
tracks the parameters of an assetAll assets have a globally unique symbol name that controls how they...
uint8_t precision
Maximum number of digits after the decimal point (must be <= 12)
std::string price_diff_percent_string(const graphene::protocol::price &old_price, const graphene::protocol::price &new_price)
std::string as_string() const