From 5c62c15ad8e4e7f13833a789446f35cefc0acc75 Mon Sep 17 00:00:00 2001 From: Ed Hennis Date: Tue, 9 Jun 2026 18:44:46 -0400 Subject: [PATCH] Future proofing: Rename Large and Enabled to Large330 and Enabled330 - If more fixes need to be made in the future, they can be added after, instead of needing to do the "rename dance", I had to do with this PR. --- include/xrpl/basics/Number.h | 50 ++++++------------------------- src/libxrpl/basics/Number.cpp | 52 ++++++++++++++++++++++++++++----- src/libxrpl/protocol/Rules.cpp | 2 +- src/test/basics/Number_test.cpp | 8 ++--- 4 files changed, 59 insertions(+), 53 deletions(-) diff --git a/include/xrpl/basics/Number.h b/include/xrpl/basics/Number.h index cb04dd9716..ccd448887a 100644 --- a/include/xrpl/basics/Number.h +++ b/include/xrpl/basics/Number.h @@ -132,14 +132,14 @@ struct MantissaRange final LargeLegacy, // Large320 can be removed when fixCleanup3_3_0 is retired Large320, - Large, + Large330, }; // This entire enum can be removed when fixCleanup3_2_0 is retired enum class CuspRoundingFix : std::uint8_t { Disabled = 0, Enabled320 = 1, - Enabled = 2, + Enabled330 = 2, }; explicit constexpr MantissaRange(MantissaScale sc) : scale(sc) @@ -168,7 +168,7 @@ private: return 15; case MantissaScale::LargeLegacy: case MantissaScale::Large320: - case MantissaScale::Large: + case MantissaScale::Large330: return 18; // LCOV_EXCL_START default: @@ -199,8 +199,8 @@ private: return CuspRoundingFix::Disabled; case MantissaScale::Large320: return CuspRoundingFix::Enabled320; - case MantissaScale::Large: - return CuspRoundingFix::Enabled; + case MantissaScale::Large330: + return CuspRoundingFix::Enabled330; default: // If called in a constexpr context, this throw assures that the build fails if an // invalid scale is used. @@ -874,43 +874,11 @@ squelch(Number const& x, Number const& limit) noexcept return x; } -inline std::string -to_string(MantissaRange::MantissaScale const& scale) -{ - switch (scale) - { - case MantissaRange::MantissaScale::Small: - return "Small"; - case MantissaRange::MantissaScale::LargeLegacy: - return "LargeLegacy"; - case MantissaRange::MantissaScale::Large320: - return "Large320"; - case MantissaRange::MantissaScale::Large: - return "Large"; - default: - throw std::runtime_error("Bad scale"); - } -} +std::string +to_string(MantissaRange::MantissaScale const& scale); -inline std::string -to_string(Number::RoundingMode const& round) -{ - switch (round) - { - enum class RoundingMode { ToNearest, TowardsZero, Downward, Upward }; - - case Number::RoundingMode::ToNearest: - return "ToNearest"; - case Number::RoundingMode::TowardsZero: - return "TowardsZero"; - case Number::RoundingMode::Downward: - return "Downward"; - case Number::RoundingMode::Upward: - return "Upward"; - default: - throw std::runtime_error("Bad rounding mode"); - } -} +std::string +to_string(Number::RoundingMode const& round); class SaveNumberRoundMode { diff --git a/src/libxrpl/basics/Number.cpp b/src/libxrpl/basics/Number.cpp index 133ec82692..c356c51722 100644 --- a/src/libxrpl/basics/Number.cpp +++ b/src/libxrpl/basics/Number.cpp @@ -31,7 +31,45 @@ namespace xrpl { thread_local Number::RoundingMode Number::mode = Number::RoundingMode::ToNearest; thread_local std::reference_wrapper Number::kRange = - MantissaRange::getMantissaRange(MantissaRange::MantissaScale::Large); + MantissaRange::getMantissaRange(MantissaRange::MantissaScale::Large330); + +std::string +to_string(MantissaRange::MantissaScale const& scale) +{ + switch (scale) + { + case MantissaRange::MantissaScale::Small: + return "Small"; + case MantissaRange::MantissaScale::LargeLegacy: + return "LargeLegacy"; + case MantissaRange::MantissaScale::Large320: + return "Large320"; + case MantissaRange::MantissaScale::Large330: + return "Large330"; + default: + throw std::runtime_error("Bad scale"); + } +} + +std::string +to_string(Number::RoundingMode const& round) +{ + switch (round) + { + enum class RoundingMode { ToNearest, TowardsZero, Downward, Upward }; + + case Number::RoundingMode::ToNearest: + return "ToNearest"; + case Number::RoundingMode::TowardsZero: + return "TowardsZero"; + case Number::RoundingMode::Downward: + return "Downward"; + case Number::RoundingMode::Upward: + return "Upward"; + default: + throw std::runtime_error("Bad rounding mode"); + } +} std::set const& MantissaRange::getAllScales() @@ -40,7 +78,7 @@ MantissaRange::getAllScales() MantissaRange::MantissaScale::Small, MantissaRange::MantissaScale::LargeLegacy, MantissaRange::MantissaScale::Large320, - MantissaRange::MantissaScale::Large, + MantissaRange::MantissaScale::Large330, }; return kScales; } @@ -92,14 +130,14 @@ MantissaRange::getRanges() } { [[maybe_unused]] - constexpr static MantissaRange kRange{MantissaRange::MantissaScale::Large}; + constexpr static MantissaRange kRange{MantissaRange::MantissaScale::Large330}; 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::kMaxRep); static_assert(kRange.max > Number::kMaxRep); - static_assert(kRange.cuspRoundingFix == CuspRoundingFix::Enabled); + static_assert(kRange.cuspRoundingFix == CuspRoundingFix::Enabled330); } return map; }(); @@ -363,7 +401,7 @@ Number::Guard::round() const noexcept { auto mode = Number::getround(); - if (cuspRoundingFix >= MantissaRange::CuspRoundingFix::Enabled && empty()) + if (cuspRoundingFix >= MantissaRange::CuspRoundingFix::Enabled330 && empty()) { // No remainder return Round::Exact; @@ -482,7 +520,7 @@ void Number::Guard::doRoundDown(bool& negative, T& mantissa, int& exponent) { auto r = round(); - if (cuspRoundingFix >= MantissaRange::CuspRoundingFix::Enabled) + if (cuspRoundingFix >= MantissaRange::CuspRoundingFix::Enabled330) { // If there was any remainder, subtract 1 from the result. This is sufficient to get the // best rounding. @@ -814,7 +852,7 @@ Number::operator+=(Number const& y) xe = ye; xn = yn; } - if (cuspRoundingFix >= MantissaRange::CuspRoundingFix::Enabled) + if (cuspRoundingFix >= MantissaRange::CuspRoundingFix::Enabled330) { // Grow xm/xe and pull digits out of the Guard until it's a little bit larger than // maxMantissa, so that normalize will have enough information to make an accurate diff --git a/src/libxrpl/protocol/Rules.cpp b/src/libxrpl/protocol/Rules.cpp index 15136115c7..5c4730e1a6 100644 --- a/src/libxrpl/protocol/Rules.cpp +++ b/src/libxrpl/protocol/Rules.cpp @@ -58,7 +58,7 @@ setCurrentTransactionRules(std::optional r) { if (enableCuspRounding3_3_0) { - return MantissaRange::MantissaScale::Large; + return MantissaRange::MantissaScale::Large330; } if (enableCuspRounding3_2_0) { diff --git a/src/test/basics/Number_test.cpp b/src/test/basics/Number_test.cpp index 266bc9bc1e..4ebdc6a73d 100644 --- a/src/test/basics/Number_test.cpp +++ b/src/test/basics/Number_test.cpp @@ -1813,7 +1813,7 @@ public: switch (scale) { case MantissaRange::MantissaScale::Large320: - case MantissaRange::MantissaScale::Large: + case MantissaRange::MantissaScale::Large330: BEAST_EXPECT(signedDifference >= 0); BEAST_EXPECT(signedDifference < pow10(product.exponent())); BEAST_EXPECT( @@ -1896,7 +1896,7 @@ public: switch (scale) { case MantissaRange::MantissaScale::Large320: - case MantissaRange::MantissaScale::Large: + case MantissaRange::MantissaScale::Large330: BEAST_EXPECT(stored >= exact); BEAST_EXPECT(diff < pow10(quotient.exponent())); break; @@ -1947,7 +1947,7 @@ public: switch (scale) { case MantissaRange::MantissaScale::Large320: - case MantissaRange::MantissaScale::Large: + case MantissaRange::MantissaScale::Large330: BEAST_EXPECT(stored <= exact); BEAST_EXPECT(diff > -pow10(quotient.exponent())); break; @@ -2005,7 +2005,7 @@ public: switch (scale) { case MantissaRange::MantissaScale::Large320: - case MantissaRange::MantissaScale::Large: + case MantissaRange::MantissaScale::Large330: BEAST_EXPECT(stored >= exact); BEAST_EXPECT(diff < pow10(quotient.exponent())); break;