diff --git a/src/test/basics/Number_test.cpp b/src/test/basics/Number_test.cpp index aabe27f294..43c9daa42e 100644 --- a/src/test/basics/Number_test.cpp +++ b/src/test/basics/Number_test.cpp @@ -1967,7 +1967,7 @@ public: } { - testcase << "normalization cusp: ToNearest and Downward disagree" << to_string(scale); + testcase << "normalization cusp: ToNearest and Downward disagree " << to_string(scale); constexpr auto kMaxRep = Number::kMaxRep; @@ -1977,34 +1977,37 @@ public: Number const above{ false, static_cast(kMaxRep) + 3, 0, Number::Unchecked{}}; - Number toNearest; - { - NumberRoundModeGuard const roundGuard{Number::RoundingMode::ToNearest}; - toNearest = Number(false, actual, 0, Number::Normalized{}); - } + auto construct = [](Number::RoundingMode mode) { + NumberRoundModeGuard const roundGuard{mode}; + return Number(false, actual, 0, Number::Normalized{}); + }; + Number const upward = construct(Number::RoundingMode::Upward); - Number downward; - { - NumberRoundModeGuard const roundGuard{Number::RoundingMode::Downward}; - downward = Number(false, actual, 0, Number::Normalized{}); - } + Number const toNearest = construct(Number::RoundingMode::ToNearest); + + Number const downward = construct(Number::RoundingMode::Downward); log << "\n" << " actual = " << actual << " (kMaxRep + 1)\n" << " below = " << below << " (kMaxRep, distance 1)\n" << " above = " << above << " (kMaxRep + 3, distance 2)\n" + << " Upward = " << upward << "\n" << " ToNearest = " << toNearest << "\n" << " Downward = " << downward << "\n\n"; + log.flush(); + + // Upward round UP + BEAST_EXPECT(upward == above); // ToNearest rounds UP when the DOWN neighbor is strictly closer - BEAST_EXPECT(toNearest == above); - BEAST_EXPECT(toNearest != below); + BEAST_EXPECT(toNearest != above); + BEAST_EXPECT(toNearest == below); // Downward undershoots: it returns a value below `below` - BEAST_EXPECT(downward < below); + BEAST_EXPECT(downward == below); // Both should have given the same answer, but they differ - BEAST_EXPECT(toNearest != downward); + BEAST_EXPECT(toNearest == downward); } }