mirror of
https://github.com/XRPLF/rippled.git
synced 2026-06-07 18:56:47 +00:00
Comment out most Number comparisons
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include <xrpl/beast/utility/Zero.h>
|
||||
#include <xrpl/beast/utility/instrumentation.h>
|
||||
|
||||
#include <array>
|
||||
@@ -407,6 +408,7 @@ public:
|
||||
return !(x == y);
|
||||
}
|
||||
|
||||
#if 0
|
||||
friend constexpr bool
|
||||
operator<(Number const& x, Number const& y) noexcept
|
||||
{
|
||||
@@ -436,6 +438,7 @@ public:
|
||||
// If equal exponents, compare mantissas
|
||||
return x.mantissa_ < y.mantissa_;
|
||||
}
|
||||
#endif
|
||||
|
||||
/** Return the sign of the amount */
|
||||
[[nodiscard]] constexpr int
|
||||
@@ -449,6 +452,7 @@ public:
|
||||
[[nodiscard]] Number
|
||||
truncate() const noexcept;
|
||||
|
||||
#if 0
|
||||
friend constexpr bool
|
||||
operator>(Number const& x, Number const& y) noexcept
|
||||
{
|
||||
@@ -466,6 +470,7 @@ public:
|
||||
{
|
||||
return !(x < y);
|
||||
}
|
||||
#endif
|
||||
|
||||
friend std::ostream&
|
||||
operator<<(std::ostream& os, Number const& x)
|
||||
@@ -815,7 +820,7 @@ Number::normalizeToRange() const
|
||||
constexpr Number
|
||||
abs(Number x) noexcept
|
||||
{
|
||||
if (x < Number{})
|
||||
if (x < beast::kZero)
|
||||
x = -x;
|
||||
return x;
|
||||
}
|
||||
@@ -846,8 +851,10 @@ power(Number const& f, unsigned n, unsigned d);
|
||||
constexpr Number
|
||||
squelch(Number const& x, Number const& limit) noexcept
|
||||
{
|
||||
#if 0
|
||||
if (abs(x) < limit)
|
||||
return Number{};
|
||||
#endif
|
||||
return x;
|
||||
}
|
||||
|
||||
|
||||
@@ -113,11 +113,15 @@ withinRelativeDistance(Quality const& calcQuality, Quality const& reqQuality, Nu
|
||||
{
|
||||
if (calcQuality == reqQuality)
|
||||
return true;
|
||||
#if 0
|
||||
auto const [min, max] = std::minmax(calcQuality, reqQuality);
|
||||
// Relative distance is (max - min)/max. Can't use basic operations
|
||||
// on Quality. Have to use Quality::rate() instead, which
|
||||
// is inverse of quality: (1/max.rate - 1/min.rate)/(1/max.rate)
|
||||
return ((min.rate() - max.rate()) / min.rate()) < dist;
|
||||
#else
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
/** Check if the relative distance between the amounts
|
||||
@@ -137,8 +141,12 @@ withinRelativeDistance(Amt const& calc, Amt const& req, Number const& dist)
|
||||
{
|
||||
if (calc == req)
|
||||
return true;
|
||||
#if 0
|
||||
auto const [min, max] = std::minmax(calc, req);
|
||||
return ((max - min) / max) < dist;
|
||||
#else
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
/** Solve quadratic equation to find takerGets or takerPays. Round
|
||||
@@ -187,16 +195,18 @@ getAMMOfferStartWithTakerGets(
|
||||
auto const c = pool.out * pool.out - (pool.in * pool.out) / targetQuality.rate();
|
||||
|
||||
auto nTakerGets = solveQuadraticEqSmallest(a, b, c);
|
||||
if (!nTakerGets || *nTakerGets <= 0)
|
||||
if (!nTakerGets || *nTakerGets <= beast::kZero)
|
||||
return std::nullopt; // LCOV_EXCL_LINE
|
||||
|
||||
auto const nTakerGetsConstraint = pool.out - pool.in / (targetQuality.rate() * f);
|
||||
if (nTakerGetsConstraint <= 0)
|
||||
if (nTakerGetsConstraint <= beast::kZero)
|
||||
return std::nullopt;
|
||||
|
||||
// Select the smallest to maximize the quality
|
||||
// Select the smallest to maximize the quality
|
||||
#if 0
|
||||
if (nTakerGetsConstraint < *nTakerGets)
|
||||
nTakerGets = nTakerGetsConstraint;
|
||||
#endif
|
||||
|
||||
auto getAmounts = [&pool, &tfee](Number const& nTakerGetsProposed) {
|
||||
// Round downward to minimize the offer and to maximize the quality.
|
||||
@@ -254,16 +264,18 @@ getAMMOfferStartWithTakerPays(
|
||||
auto const c = pool.in * pool.in - pool.in * pool.out * targetQuality.rate();
|
||||
|
||||
auto nTakerPays = solveQuadraticEqSmallest(a, b, c);
|
||||
if (!nTakerPays || nTakerPays <= 0)
|
||||
if (!nTakerPays || *nTakerPays <= beast::kZero)
|
||||
return std::nullopt; // LCOV_EXCL_LINE
|
||||
|
||||
auto const nTakerPaysConstraint = pool.out * targetQuality.rate() - pool.in / f;
|
||||
if (nTakerPaysConstraint <= 0)
|
||||
if (nTakerPaysConstraint <= beast::kZero)
|
||||
return std::nullopt;
|
||||
|
||||
#if 0
|
||||
// Select the smallest to maximize the quality
|
||||
if (nTakerPaysConstraint < *nTakerPays)
|
||||
nTakerPays = nTakerPaysConstraint;
|
||||
#endif
|
||||
|
||||
auto getAmounts = [&pool, &tfee](Number const& nTakerPaysProposed) {
|
||||
// Round downward to minimize the offer and to maximize the quality.
|
||||
@@ -319,23 +331,26 @@ changeSpotPriceQuality(
|
||||
auto const b = pool.in * (1 + f);
|
||||
Number const c = pool.in * pool.in - pool.in * pool.out * quality.rate();
|
||||
auto const res = b * b - 4 * a * c;
|
||||
if (res < 0)
|
||||
if (res < beast::kZero)
|
||||
{
|
||||
return std::nullopt; // LCOV_EXCL_LINE
|
||||
}
|
||||
if (auto const nTakerPaysPropose = (-b + root2(res)) / (2 * a); nTakerPaysPropose > 0)
|
||||
if (auto const nTakerPaysPropose = (-b + root2(res)) / (2 * a);
|
||||
nTakerPaysPropose > beast::kZero)
|
||||
{
|
||||
auto const nTakerPays = [&]() {
|
||||
// The fee might make the AMM offer quality less than CLOB
|
||||
// quality. Therefore, AMM offer has to satisfy this constraint:
|
||||
// o / i >= q. Substituting o with swapAssetIn() gives: i <= O /
|
||||
// q - I / (1 - fee).
|
||||
// The fee might make the AMM offer quality less than CLOB
|
||||
// quality. Therefore, AMM offer has to satisfy this constraint:
|
||||
// o / i >= q. Substituting o with swapAssetIn() gives: i <= O /
|
||||
// q - I / (1 - fee).
|
||||
#if 0
|
||||
auto const nTakerPaysConstraint = pool.out * quality.rate() - pool.in / f;
|
||||
if (nTakerPaysPropose > nTakerPaysConstraint)
|
||||
return nTakerPaysConstraint;
|
||||
#endif
|
||||
return nTakerPaysPropose;
|
||||
}();
|
||||
if (nTakerPays <= 0)
|
||||
if (nTakerPays <= beast::kZero)
|
||||
{
|
||||
JLOG(j.trace()) << "changeSpotPriceQuality calc failed: " << to_string(pool.in)
|
||||
<< " " << to_string(pool.out) << " " << quality << " " << tfee;
|
||||
|
||||
@@ -136,11 +136,13 @@ IOUAmount::operator==(IOUAmount const& other) const
|
||||
return exponent_ == other.exponent_ && mantissa_ == other.mantissa_;
|
||||
}
|
||||
|
||||
#if 0
|
||||
inline bool
|
||||
IOUAmount::operator<(IOUAmount const& other) const
|
||||
{
|
||||
return Number{*this} < Number{other};
|
||||
}
|
||||
#endif
|
||||
|
||||
inline IOUAmount::
|
||||
operator bool() const noexcept
|
||||
|
||||
@@ -37,7 +37,7 @@ namespace xrpl {
|
||||
*/
|
||||
class ValidVault
|
||||
{
|
||||
static constexpr Number kZero{};
|
||||
static constexpr beast::Zero kZero{};
|
||||
|
||||
struct Vault final
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user