20 #include <ripple/protocol/Quality.h>
31 Quality::Quality (Amounts
const& amount)
45 Quality::operator++ (
int)
61 Quality::operator-- (
int)
69 Quality::ceil_in (Amounts
const& amount, STAmount
const& limit)
const
71 if (amount.in > limit)
74 limit,
rate(), amount.out.issue (),
true));
76 if (result.out > amount.out)
77 result.out = amount.out;
78 assert (result.in == limit);
81 assert (amount.in <= limit);
86 Quality::ceil_out (Amounts
const& amount, STAmount
const& limit)
const
88 if (amount.out > limit)
91 limit,
rate(), amount.in.issue (),
true), limit);
93 if (result.in > amount.in)
94 result.in = amount.in;
95 assert (result.out == limit);
98 assert (amount.out <= limit);
105 STAmount const lhs_rate (lhs.rate ());
106 assert (lhs_rate != beast::zero);
108 STAmount const rhs_rate (rhs.rate ());
109 assert (rhs_rate != beast::zero);
112 lhs_rate, rhs_rate, lhs_rate.
issue (),
true));
114 std::uint64_t const stored_exponent (rate.exponent () + 100);
117 assert ((stored_exponent > 0) && (stored_exponent <= 255));
119 return Quality ((stored_exponent << (64 - 8)) | stored_mantissa);
123 Quality::round (
int digits)
const
146 auto exponent = m_value >> (64 - 8);
147 auto mantissa = m_value & 0x00ffffffffffffffULL;
148 mantissa += mod[digits] - 1;
149 mantissa -= (mantissa % mod[digits]);
151 return Quality{(exponent << (64 - 8)) | mantissa};