mirror of
https://github.com/XRPLF/rippled.git
synced 2026-06-03 16:56:48 +00:00
Fix clang-tidy issues, and more AI complaints
This commit is contained in:
@@ -10,9 +10,11 @@
|
||||
#include <iterator>
|
||||
#include <limits>
|
||||
#include <numeric>
|
||||
#include <set>
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
#include <type_traits>
|
||||
#include <unordered_map>
|
||||
#include <utility>
|
||||
|
||||
#ifdef _MSC_VER
|
||||
@@ -34,18 +36,18 @@ thread_local std::reference_wrapper<MantissaRange const> Number::kRANGE =
|
||||
std::set<MantissaRange::MantissaScale> const&
|
||||
MantissaRange::getAllScales()
|
||||
{
|
||||
static std::set<MantissaRange::MantissaScale> const scales = {
|
||||
static std::set<MantissaRange::MantissaScale> const kSCALES = {
|
||||
MantissaRange::MantissaScale::Small,
|
||||
MantissaRange::MantissaScale::LargeLegacy,
|
||||
MantissaRange::MantissaScale::Large,
|
||||
};
|
||||
return scales;
|
||||
return kSCALES;
|
||||
}
|
||||
|
||||
std::unordered_map<MantissaRange::MantissaScale, MantissaRange> const&
|
||||
MantissaRange::getRanges()
|
||||
{
|
||||
static auto const map = []() {
|
||||
static auto const kMAP = []() {
|
||||
std::unordered_map<MantissaScale, MantissaRange> map;
|
||||
for (auto const scale : getAllScales())
|
||||
{
|
||||
@@ -56,41 +58,41 @@ MantissaRange::getRanges()
|
||||
// created correctly, but nothing else.
|
||||
{
|
||||
[[maybe_unused]]
|
||||
constexpr static MantissaRange range{MantissaRange::MantissaScale::Small};
|
||||
static_assert(isPowerOfTen(range.min));
|
||||
static_assert(range.min == 1'000'000'000'000'000LL);
|
||||
static_assert(range.max == 9'999'999'999'999'999LL);
|
||||
static_assert(range.log == 15);
|
||||
static_assert(range.min < Number::kMAX_REP);
|
||||
static_assert(range.max < Number::kMAX_REP);
|
||||
static_assert(range.cuspRoundingFixEnabled == CuspRoundingFix::Disabled);
|
||||
constexpr static MantissaRange kRANGE{MantissaRange::MantissaScale::Small};
|
||||
static_assert(isPowerOfTen(kRANGE.min));
|
||||
static_assert(kRANGE.min == 1'000'000'000'000'000LL);
|
||||
static_assert(kRANGE.max == 9'999'999'999'999'999LL);
|
||||
static_assert(kRANGE.log == 15);
|
||||
static_assert(kRANGE.min < Number::kMAX_REP);
|
||||
static_assert(kRANGE.max < Number::kMAX_REP);
|
||||
static_assert(kRANGE.cuspRoundingFixEnabled == CuspRoundingFix::Disabled);
|
||||
}
|
||||
{
|
||||
[[maybe_unused]]
|
||||
constexpr static MantissaRange range{MantissaRange::MantissaScale::LargeLegacy};
|
||||
static_assert(isPowerOfTen(range.min));
|
||||
static_assert(range.min == 1'000'000'000'000'000'000ULL);
|
||||
static_assert(range.max == rep(9'999'999'999'999'999'999ULL));
|
||||
static_assert(range.log == 18);
|
||||
static_assert(range.min < Number::kMAX_REP);
|
||||
static_assert(range.max > Number::kMAX_REP);
|
||||
static_assert(range.cuspRoundingFixEnabled == CuspRoundingFix::Disabled);
|
||||
constexpr static MantissaRange kRANGE{MantissaRange::MantissaScale::LargeLegacy};
|
||||
static_assert(isPowerOfTen(kRANGE.min));
|
||||
static_assert(kRANGE.min == 1'000'000'000'000'000'000ULL);
|
||||
static_assert(kRANGE.max == rep(9'999'999'999'999'999'999ULL));
|
||||
static_assert(kRANGE.log == 18);
|
||||
static_assert(kRANGE.min < Number::kMAX_REP);
|
||||
static_assert(kRANGE.max > Number::kMAX_REP);
|
||||
static_assert(kRANGE.cuspRoundingFixEnabled == CuspRoundingFix::Disabled);
|
||||
}
|
||||
{
|
||||
[[maybe_unused]]
|
||||
constexpr static MantissaRange range{MantissaRange::MantissaScale::Large};
|
||||
static_assert(isPowerOfTen(range.min));
|
||||
static_assert(range.min == 1'000'000'000'000'000'000ULL);
|
||||
static_assert(range.max == rep(9'999'999'999'999'999'999ULL));
|
||||
static_assert(range.log == 18);
|
||||
static_assert(range.min < Number::kMAX_REP);
|
||||
static_assert(range.max > Number::kMAX_REP);
|
||||
static_assert(range.cuspRoundingFixEnabled == CuspRoundingFix::Enabled);
|
||||
constexpr static MantissaRange kRANGE{MantissaRange::MantissaScale::Large};
|
||||
static_assert(isPowerOfTen(kRANGE.min));
|
||||
static_assert(kRANGE.min == 1'000'000'000'000'000'000ULL);
|
||||
static_assert(kRANGE.max == rep(9'999'999'999'999'999'999ULL));
|
||||
static_assert(kRANGE.log == 18);
|
||||
static_assert(kRANGE.min < Number::kMAX_REP);
|
||||
static_assert(kRANGE.max > Number::kMAX_REP);
|
||||
static_assert(kRANGE.cuspRoundingFixEnabled == CuspRoundingFix::Enabled);
|
||||
}
|
||||
return map;
|
||||
}();
|
||||
|
||||
return map;
|
||||
return kMAP;
|
||||
}
|
||||
|
||||
MantissaRange const&
|
||||
|
||||
@@ -38,12 +38,20 @@ setCurrentTransactionRules(std::optional<Rules> r)
|
||||
// Make global changes associated with the rules before the value is moved.
|
||||
// Push the appropriate setting, instead of having the class pull every time
|
||||
// the value is needed. That could get expensive fast.
|
||||
|
||||
// The improved accuracy that will come from enabling large
|
||||
// mantissas is a goal separate from SAV and LP. It was originally
|
||||
// only tied to those two amendments to avoid needing a new
|
||||
// amendment of it's own, and because they require that behavior.
|
||||
// Because fixCleanup3_2_0 fixes a separate bug related to the large
|
||||
// mantissas, that can take precedence and activate the large
|
||||
// mantissas even in the absence of the other two amendments.
|
||||
bool const enableCuspRoundingFix = !r || r->enabled(fixCleanup3_2_0);
|
||||
bool const enableLargeNumbers = enableCuspRoundingFix ||
|
||||
bool const enableVaultNumbers = enableCuspRoundingFix ||
|
||||
(r->enabled(featureSingleAssetVault) || r->enabled(featureLendingProtocol));
|
||||
Number::setMantissaScale(
|
||||
enableCuspRoundingFix ? MantissaRange::MantissaScale::Large
|
||||
: enableLargeNumbers ? MantissaRange::MantissaScale::LargeLegacy
|
||||
: enableVaultNumbers ? MantissaRange::MantissaScale::LargeLegacy
|
||||
: MantissaRange::MantissaScale::Small);
|
||||
|
||||
*getCurrentTransactionRulesRef() = std::move(r);
|
||||
|
||||
@@ -65,7 +65,7 @@ namespace xrpl::test {
|
||||
/**
|
||||
* Tests of AMM that use offers too.
|
||||
*/
|
||||
struct AMMExtended_test : public jtx::AMMTest
|
||||
class AMMExtended_test : public jtx::AMMTest
|
||||
{
|
||||
// Use small Number mantissas for the life of this test.
|
||||
NumberMantissaScaleGuard const sg{xrpl::MantissaRange::MantissaScale::Small};
|
||||
|
||||
@@ -31,7 +31,7 @@ class Number_test : public beast::unit_test::Suite
|
||||
int count = 0;
|
||||
for (auto it = s.rbegin(); it != s.rend(); ++it)
|
||||
{
|
||||
if (count && count % 3 == 0)
|
||||
if (count != 0 && count % 3 == 0)
|
||||
out.insert(out.begin(), '_');
|
||||
out.insert(out.begin(), *it);
|
||||
++count;
|
||||
@@ -222,7 +222,7 @@ public:
|
||||
{Number{Number::kMAX_REP}, Number{6, -1}, Number{Number::kMAX_REP / 10, 1}},
|
||||
});
|
||||
auto const cLargeCorrected = std::to_array<Case>({
|
||||
{Number{Number::kMAX_REP}, Number{6, -1}, Number{Number::kMAX_REP / 10 + 1, 1}},
|
||||
{Number{Number::kMAX_REP}, Number{6, -1}, Number{(Number::kMAX_REP / 10) + 1, 1}},
|
||||
});
|
||||
auto test = [this](auto const& c) {
|
||||
for (auto const& [x, y, z] : c)
|
||||
@@ -241,9 +241,13 @@ public:
|
||||
{
|
||||
test(cLarge);
|
||||
if (scale == MantissaRange::MantissaScale::LargeLegacy)
|
||||
{
|
||||
test(cLargeLegacy);
|
||||
}
|
||||
else
|
||||
{
|
||||
test(cLargeCorrected);
|
||||
}
|
||||
}
|
||||
{
|
||||
bool caught = false;
|
||||
@@ -1589,16 +1593,16 @@ public:
|
||||
NumberMantissaScaleGuard const mg{MantissaRange::MantissaScale::Large};
|
||||
NumberRoundModeGuard const rg{Number::RoundingMode::Upward};
|
||||
|
||||
constexpr std::int64_t aValue = 1'000'000'000'000'049'863LL;
|
||||
constexpr std::int64_t bValue = 9'223'372'036'854'315'903LL;
|
||||
constexpr std::int64_t kA_VALUE = 1'000'000'000'000'049'863LL;
|
||||
constexpr std::int64_t kB_VALUE = 9'223'372'036'854'315'903LL;
|
||||
|
||||
// Public conversion operator: STAmount::operator Number() const.
|
||||
Number const a = aValue;
|
||||
Number const b = bValue;
|
||||
Number const a = kA_VALUE;
|
||||
Number const b = kB_VALUE;
|
||||
Number const product = a * b;
|
||||
|
||||
// Exact reference in BigInt.
|
||||
BigInt const exactProduct = BigInt(aValue) * BigInt(bValue);
|
||||
BigInt const exactProduct = BigInt(kA_VALUE) * BigInt(kB_VALUE);
|
||||
|
||||
// What Number actually stored.
|
||||
BigInt storedValue = BigInt(product.mantissa());
|
||||
@@ -1608,8 +1612,8 @@ public:
|
||||
BigInt const signedDifference = storedValue - exactProduct;
|
||||
|
||||
log << "\n"
|
||||
<< " a = " << fmt(BigInt(aValue)) << "\n"
|
||||
<< " b = " << fmt(BigInt(bValue)) << "\n"
|
||||
<< " a = " << fmt(BigInt(kA_VALUE)) << "\n"
|
||||
<< " b = " << fmt(BigInt(kB_VALUE)) << "\n"
|
||||
<< " exact a*b = " << fmt(exactProduct) << "\n"
|
||||
<< " stored = " << fmt(storedValue) << "\n"
|
||||
<< " stored - exact = " << fmt(signedDifference) << "\n"
|
||||
|
||||
Reference in New Issue
Block a user