Fix formatting, add an assert

This commit is contained in:
Ed Hennis
2026-06-06 15:37:03 -04:00
parent c165af497e
commit d7ce0e2dd3
2 changed files with 27 additions and 14 deletions

View File

@@ -473,6 +473,9 @@ Number::Guard::doRoundDown(bool& negative, T& mantissa, int& exponent)
{
// If there was any remainder, subtract 1 from the result. This is sufficient to get the
// best rounding.
XRPL_ASSERT(
empty() || mantissa > maxMantissa_,
"xrpl::Number::Guard::doRoundDown : mantissa is expected size");
if (r != Round::Exact)
{
--mantissa;

View File

@@ -1981,14 +1981,19 @@ public:
case MantissaRange::MantissaScale::Small:
case MantissaRange::MantissaScale::LargeLegacy: {
// Without the fix, all the results but one round up
for (auto const& [r, sum] : sums) {
if (r == Number::RoundingMode::Downward) {
// Downward works because the Guard sign is negative, and Downward returns Up
// instead of Down if negative and there's a remainder, whereas TowardsZero
// always returns Down.
BEAST_EXPECTS(sums.at(Number::RoundingMode::Downward).first < exact, to_string(r));
for (auto const& [r, sum] : sums)
{
if (r == Number::RoundingMode::Downward)
{
// Downward works because the Guard sign is negative, and Downward
// returns Up instead of Down if negative and there's a remainder,
// whereas TowardsZero always returns Down.
BEAST_EXPECTS(
sums.at(Number::RoundingMode::Downward).first < exact,
to_string(r));
}
else {
else
{
BEAST_EXPECTS(sums.at(r).first > exact, to_string(r));
}
}
@@ -2058,14 +2063,19 @@ public:
{
case MantissaRange::MantissaScale::Small:
case MantissaRange::MantissaScale::LargeLegacy: {
for (auto const& [r, sum] : sums) {
if (r == Number::RoundingMode::Downward) {
// Downward works because the Guard sign is negative, and Downward returns Up
// instead of Down if negative and there's a remainder, whereas TowardsZero
// always returns Down.
BEAST_EXPECTS(sums.at(Number::RoundingMode::Downward).first < exact, to_string(r));
for (auto const& [r, sum] : sums)
{
if (r == Number::RoundingMode::Downward)
{
// Downward works because the Guard sign is negative, and Downward
// returns Up instead of Down if negative and there's a remainder,
// whereas TowardsZero always returns Down.
BEAST_EXPECTS(
sums.at(Number::RoundingMode::Downward).first < exact,
to_string(r));
}
else {
else
{
BEAST_EXPECTS(sums.at(r).first > exact, to_string(r));
}
}