From fe64b99147e5930e0fb4b37540db2df9ec05ab22 Mon Sep 17 00:00:00 2001 From: Ed Hennis Date: Sat, 6 Jun 2026 16:19:25 -0400 Subject: [PATCH] Reorganize the subtraction tests --- src/test/basics/Number_test.cpp | 40 ++++++++++++++++----------------- 1 file changed, 19 insertions(+), 21 deletions(-) diff --git a/src/test/basics/Number_test.cpp b/src/test/basics/Number_test.cpp index d8b87c5624..4b929799ac 100644 --- a/src/test/basics/Number_test.cpp +++ b/src/test/basics/Number_test.cpp @@ -1976,45 +1976,43 @@ public: } log.flush(); - switch (scale) + for (auto const& [r, sum] : sums) { - case MantissaRange::MantissaScale::Small: - case MantissaRange::MantissaScale::LargeLegacy: { - // Without the fix, all the results but one round up - for (auto const& [r, sum] : sums) - { + auto const epsilon = pow10(sum.second.exponent()); + auto diff = sum.first - exact; + auto const rLabel = to_string(r); + switch (scale) + { + case MantissaRange::MantissaScale::Small: + case MantissaRange::MantissaScale::LargeLegacy: { + // Without the fix, all the results but one round up 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)); + BEAST_EXPECTS(sum.first < exact, rLabel); + BEAST_EXPECTS(diff == -(epsilon - 1), rLabel); } else { - BEAST_EXPECTS(sums.at(r).first > exact, to_string(r)); + BEAST_EXPECTS(sum.first > exact, rLabel); + BEAST_EXPECTS(diff == 1, rLabel); } + break; } - break; - } - default: { - for (auto const& [r, sum] : sums) - { - auto const epsilon = pow10(sum.second.exponent()); + default: { BEAST_EXPECT(epsilon == 100); - auto diff = sum.first - exact; switch (r) { case Number::RoundingMode::Upward: case Number::RoundingMode::ToNearest: - BEAST_EXPECTS(sum.first > exact, to_string(r)); - BEAST_EXPECTS(diff < epsilon, to_string(r)); + BEAST_EXPECTS(sum.first > exact, rLabel); + BEAST_EXPECTS(diff == 1, rLabel); break; default: - BEAST_EXPECTS(sum.first < exact, to_string(r)); - BEAST_EXPECTS(-diff < epsilon, to_string(r)); + BEAST_EXPECTS(sum.first < exact, rLabel); + BEAST_EXPECTS(diff == -(epsilon - 1), rLabel); } } }