mirror of
https://github.com/XRPLF/rippled.git
synced 2026-07-01 19:42:12 +00:00
Address AI review feedback: mantissa assertion, test resiliency
- Move code around and add comments in `bringIntoRange` to make it clearer that mantissas should not be 0, but fall back gracefully in non-debug builds if they are. - Make a test that checks for Large330 future-proof if more scales are added later.
This commit is contained in:
@@ -528,17 +528,20 @@ void
|
||||
Number::Guard::bringIntoRange(bool& negative, T& mantissa, int& exponent) const
|
||||
{
|
||||
// Bring mantissa back into the minMantissa / maxMantissa range AFTER
|
||||
// rounding. Mantissa should never be 0.
|
||||
XRPL_ASSERT(mantissa != 0, "xrpl::Number::Guard::bringIntoRange : valid mantissa");
|
||||
if (mantissa < minMantissa)
|
||||
// rounding.
|
||||
if (mantissa < minMantissa &&
|
||||
(cuspRoundingFix < MantissaRange::CuspRoundingFix::Enabled330 || mantissa != 0))
|
||||
{
|
||||
mantissa *= 10;
|
||||
--exponent;
|
||||
}
|
||||
// mantissa should never be 0, but if it _is_ make the result kZero.
|
||||
// mantissa should never be 0, but if it _is_ assert, but fall back to making the result kZero.
|
||||
if (exponent < kMinExponent ||
|
||||
(cuspRoundingFix >= MantissaRange::CuspRoundingFix::Enabled330 && mantissa == 0))
|
||||
{
|
||||
// Engineers: If you hit this assert, you probably did something wrong in the operation
|
||||
// leading up to the rounding work.
|
||||
XRPL_ASSERT(mantissa != 0, "xrpl::Number::Guard::bringIntoRange : valid mantissa");
|
||||
static constexpr Number kZero = Number{};
|
||||
|
||||
negative = kZero.negative_;
|
||||
|
||||
@@ -1452,7 +1452,7 @@ class LoanBroker_test : public beast::unit_test::Suite
|
||||
env(tx2, Ter(temINVALID));
|
||||
}
|
||||
|
||||
if (Number::getMantissaScale() == MantissaRange::MantissaScale::Large330)
|
||||
if (Number::getMantissaScale() >= MantissaRange::MantissaScale::Large330)
|
||||
{
|
||||
// For the Large330 scale, 2^63 rounds _down_ to Number::kMaxRep
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user