Rework subtraction rounding (again) for more accuracy

- Go back to the old method of computing the mantissa, but when post
  processing, expand the mantissa to slightly larger than maxMantissa,
  then in doRoundDown, if the result is not exact, subtract one.
  Finally, let doNormalize figure out the rounding of the result.
This commit is contained in:
Ed Hennis
2026-06-05 18:02:45 -04:00
parent 74c66d0944
commit 012c67a7eb
3 changed files with 254 additions and 89 deletions

View File

@@ -877,6 +877,26 @@ to_string(MantissaRange::MantissaScale const& scale)
}
}
inline std::string
to_string(Number::RoundingMode const& round)
{
switch (round)
{
enum class RoundingMode { ToNearest, TowardsZero, Downward, Upward };
case Number::RoundingMode::ToNearest:
return "ToNearest";
case Number::RoundingMode::TowardsZero:
return "TowardsZero";
case Number::RoundingMode::Downward:
return "Downward";
case Number::RoundingMode::Upward:
return "Upward";
default:
throw std::runtime_error("Bad rounding mode");
}
}
class SaveNumberRoundMode
{
Number::RoundingMode mode_;