3#include <xrpl/beast/utility/Zero.h>
4#include <xrpl/beast/utility/instrumentation.h>
5#include <xrpl/protocol/AmountConversions.h>
6#include <xrpl/protocol/STAmount.h>
27template <
class In,
class Out>
71template <
class In,
class Out>
75 return lhs.in == rhs.in && lhs.out == rhs.out;
81#define QUALITY_ONE 1'000'000'000
122 template <
class In,
class Out>
131 template <
class In,
class Out>
172 round(
int tickSize)
const;
182 template <
class In,
class Out>
192 template <
class In,
class Out>
204 template <
class In,
class Out>
214 template <
class In,
class Out>
222 template <
class In,
class Out,
class Lim,
typename FnPtr, std::same_as<
bool>... Round>
229 Round...
round)
const;
240 return lhs.value_ > rhs.value_;
246 return lhs.value_ < rhs.value_;
264 return lhs.value_ == rhs.value_;
270 os << quality.value_;
280 q1.
value_ > 0 && q2.
value_ > 0,
"xrpl::Quality::relativeDistance : minimum inputs");
290 auto const minVMantissa = mantissa(minV);
291 auto const maxVMantissa = mantissa(maxV);
292 auto const expDiff = exponent(maxV) - exponent(minV);
294 auto const minVD =
static_cast<double>(minVMantissa);
296 (expDiff != 0) ? maxVMantissa * pow(10, expDiff) :
static_cast<double>(maxVMantissa);
301 return (maxVD - minVD) / minVD;
305template <
class In,
class Out,
class Lim,
typename FnPtr, std::same_as<
bool>... Round>
312 Round... roundUp)
const
314 if (limitCmp <= limit)
321 Amounts const stRes = ((*this).*ceilFunction)(stAmt, stLim, roundUp...);
325template <
class In,
class Out>
336template <
class In,
class Out>
347template <
class In,
class Out>
355 return ceil_TAmounts_helper(amount, limit, amount.
out, kCeilOutFnPtr);
358template <
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)
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)
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)