diff --git a/src/libxrpl/basics/Number.cpp b/src/libxrpl/basics/Number.cpp index d43eebc314..9fc464f487 100644 --- a/src/libxrpl/basics/Number.cpp +++ b/src/libxrpl/basics/Number.cpp @@ -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; diff --git a/src/test/basics/Number_test.cpp b/src/test/basics/Number_test.cpp index aa57af01b3..d8b87c5624 100644 --- a/src/test/basics/Number_test.cpp +++ b/src/test/basics/Number_test.cpp @@ -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)); } }