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.
This commit is contained in:
Ed Hennis
2026-06-09 18:44:46 -04:00
parent 772e0c30f7
commit 5c62c15ad8
4 changed files with 59 additions and 53 deletions

View File

@@ -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
{

View File

@@ -31,7 +31,45 @@ namespace xrpl {
thread_local Number::RoundingMode Number::mode = Number::RoundingMode::ToNearest;
thread_local std::reference_wrapper<MantissaRange const> 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<MantissaRange::MantissaScale> 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

View File

@@ -58,7 +58,7 @@ setCurrentTransactionRules(std::optional<Rules> r)
{
if (enableCuspRounding3_3_0)
{
return MantissaRange::MantissaScale::Large;
return MantissaRange::MantissaScale::Large330;
}
if (enableCuspRounding3_2_0)
{

View File

@@ -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<BigInt>(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;