Include rounding in failed unit tests

This commit is contained in:
Ed Hennis
2026-06-06 14:33:31 -04:00
parent 184f936362
commit e77b154edc

View File

@@ -2077,13 +2077,17 @@ public:
case MantissaRange::MantissaScale::Small:
case MantissaRange::MantissaScale::LargeLegacy: {
// Without the fix, all the results but one round up
BEAST_EXPECT(sums.at(Number::RoundingMode::TowardsZero).first > exact);
BEAST_EXPECT(sums.at(Number::RoundingMode::Upward).first > exact);
BEAST_EXPECT(sums.at(Number::RoundingMode::ToNearest).first > exact);
// 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_EXPECT(sums.at(Number::RoundingMode::Downward).first < exact);
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 {
BEAST_EXPECTS(sums.at(r).first > exact, to_string(r));
}
}
break;
}
default: {
@@ -2096,12 +2100,12 @@ public:
{
case Number::RoundingMode::Upward:
case Number::RoundingMode::ToNearest:
BEAST_EXPECT(sum.first > exact);
BEAST_EXPECT(diff < epsilon);
BEAST_EXPECTS(sum.first > exact, to_string(r));
BEAST_EXPECTS(diff < epsilon, to_string(r));
break;
default:
BEAST_EXPECT(sum.first < exact);
BEAST_EXPECT(-diff < epsilon);
BEAST_EXPECTS(sum.first < exact, to_string(r));
BEAST_EXPECTS(-diff < epsilon, to_string(r));
}
}
}
@@ -2150,14 +2154,17 @@ public:
{
case MantissaRange::MantissaScale::Small:
case MantissaRange::MantissaScale::LargeLegacy: {
// Without the fix, all the results but one round up
BEAST_EXPECT(sums.at(Number::RoundingMode::TowardsZero).first > exact);
BEAST_EXPECT(sums.at(Number::RoundingMode::Upward).first > exact);
BEAST_EXPECT(sums.at(Number::RoundingMode::ToNearest).first > exact);
// 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_EXPECT(sums.at(Number::RoundingMode::Downward).first < exact);
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 {
BEAST_EXPECTS(sums.at(r).first > exact, to_string(r));
}
}
break;
}
default: {
@@ -2169,12 +2176,12 @@ public:
{
case Number::RoundingMode::Upward:
case Number::RoundingMode::ToNearest:
BEAST_EXPECT(sum.first > exact);
BEAST_EXPECT(diff < epsilon);
BEAST_EXPECTS(sum.first > exact, to_string(r));
BEAST_EXPECTS(diff < epsilon, to_string(r));
break;
default:
BEAST_EXPECT(sum.first < exact);
BEAST_EXPECT(-diff < epsilon);
BEAST_EXPECTS(sum.first < exact, to_string(r));
BEAST_EXPECTS(-diff < epsilon, to_string(r));
}
}
}