3#include <xrpl/protocol/AmountConversions.h>
4#include <xrpl/protocol/IOUAmount.h>
5#include <xrpl/protocol/STAmount.h>
6#include <xrpl/protocol/XRPAmount.h>
24template <
class In,
class Out>
41 return in <= beast::kZero ||
out <= beast::kZero;
66template <
class In,
class Out>
70 return lhs.in == rhs.in && lhs.out == rhs.out;
73template <
class In,
class Out>
83#define QUALITY_ONE 1'000'000'000
117 template <
class In,
class Out>
124 template <
class In,
class Out>
158 round(
int tickSize)
const;
167 template <
class In,
class Out>
177 template <
class In,
class Out>
188 template <
class In,
class Out>
198 template <
class In,
class Out>
206 template <
class In,
class Out,
class Lim,
typename FnPtr, std::same_as<
bool>... Round>
213 Round...
round)
const;
223 return lhs.value_ > rhs.value_;
229 return lhs.value_ < rhs.value_;
247 return lhs.value_ == rhs.value_;
253 return !(lhs == rhs);
259 os << quality.value_;
269 q1.
value_ > 0 && q2.
value_ > 0,
"xrpl::Quality::relativeDistance : minimum inputs");
279 auto const minVMantissa = mantissa(minV);
280 auto const maxVMantissa = mantissa(maxV);
281 auto const expDiff = exponent(maxV) - exponent(minV);
283 double const minVD =
static_cast<double>(minVMantissa);
285 (expDiff != 0) ? maxVMantissa * pow(10, expDiff) :
static_cast<double>(maxVMantissa);
290 return (maxVD - minVD) / minVD;
294template <
class In,
class Out,
class Lim,
typename FnPtr, std::same_as<
bool>... Round>
301 Round... roundUp)
const
303 if (limitCmp <= limit)
310 Amounts const stRes = ((*this).*ceilFunction)(stAmt, stLim, roundUp...);
314template <
class In,
class Out>
325template <
class In,
class Out>
336template <
class In,
class Out>
344 return ceil_TAmounts_helper(amount, limit, amount.
out, kCeilOutFnPtr);
347template <
class In,
class Out>
Represents the logical ratio of output currency to input currency.
Quality & operator++()
Advances to the next higher quality level.
static int const kMaxTickSize
TAmounts< In, Out > ceilTAmountsHelper(TAmounts< In, Out > const &amount, Lim const &limit, Lim const &limitCmp, FnPtr ceilFunction, Round... round) const
STAmount rate() const
Returns the quality as STAmount.
Quality round(int tickSize) const
Returns the quality rounded up to the specified number of decimal digits.
friend std::ostream & operator<<(std::ostream &os, Quality const &quality)
Amounts ceilOut(Amounts const &amount, STAmount const &limit) const
Returns the scaled amount with out capped.
Amounts ceilIn(Amounts const &amount, STAmount const &limit) const
Returns the scaled amount with in capped.
friend bool operator<=(Quality const &lhs, Quality const &rhs) noexcept
friend bool operator<(Quality const &lhs, Quality const &rhs) noexcept
Returns true if lhs is lower quality than rhs.
Amounts ceilOutStrict(Amounts const &amount, STAmount const &limit, bool roundUp) const
Amounts ceilInStrict(Amounts const &amount, STAmount const &limit, bool roundUp) const
Quality(TAmounts< In, Out > const &amount)
Create a quality from the ratio of two amounts.
static int const kMinTickSize
friend bool operator>=(Quality const &lhs, Quality const &rhs) noexcept
friend double relativeDistance(Quality const &q1, Quality const &q2)
friend bool operator!=(Quality const &lhs, Quality const &rhs) noexcept
Quality & operator--()
Advances to the next lower quality level.
Quality(Out const &out, In const &in)
Create a quality from the ratio of two amounts.
friend bool operator>(Quality const &lhs, Quality const &rhs) noexcept
friend bool operator==(Quality const &lhs, Quality const &rhs) noexcept
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
constexpr bool operator==(BaseUInt< Bits, Tag > const &lhs, BaseUInt< Bits, Tag > const &rhs)
TAmounts< STAmount, STAmount > Amounts
T toAmount(STAmount const &amt)=delete
STAmount amountFromQuality(std::uint64_t rate)
bool operator!=(Buffer const &lhs, Buffer const &rhs) noexcept
Quality composedQuality(Quality const &lhs, Quality const &rhs)
Calculate the quality of a two-hop path given the two hops.
STAmount toSTAmount(IOUAmount const &iou, Asset const &asset)
Zero allows classes to offer efficient comparisons to zero.
Represents a pair of input and output currencies.
bool empty() const noexcept
Returns true if either quantity is not positive.
TAmounts(beast::Zero, beast::Zero)
TAmounts & operator+=(TAmounts const &rhs)
TAmounts & operator-=(TAmounts const &rhs)