Skip to content

Commit

Permalink
[FOLD] Address reviewer comments
Browse files Browse the repository at this point in the history
  • Loading branch information
HowardHinnant committed Oct 19, 2022
1 parent f99d623 commit efd5187
Showing 1 changed file with 22 additions and 24 deletions.
46 changes: 22 additions & 24 deletions src/ripple/basics/impl/IOUAmount.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,36 +120,34 @@ IOUAmount::operator+=(IOUAmount const& other)
if (*stNumberSwitchover)
{
*this = IOUAmount{Number{*this} + Number{other}};
return *this;
}
else
{
auto m = other.mantissa_;
auto e = other.exponent_;

while (exponent_ < e)
{
mantissa_ /= 10;
++exponent_;
}
auto m = other.mantissa_;
auto e = other.exponent_;

while (e < exponent_)
{
m /= 10;
++e;
}
while (exponent_ < e)
{
mantissa_ /= 10;
++exponent_;
}

// This addition cannot overflow an std::int64_t but we may throw from
// normalize if the result isn't representable.
mantissa_ += m;
while (e < exponent_)
{
m /= 10;
++e;
}

if (mantissa_ >= -10 && mantissa_ <= 10)
{
*this = beast::zero;
return *this;
}
// This addition cannot overflow an std::int64_t but we may throw from
// normalize if the result isn't representable.
mantissa_ += m;

normalize();
if (mantissa_ >= -10 && mantissa_ <= 10)
{
*this = beast::zero;
return *this;
}

normalize();
return *this;
}

Expand Down

0 comments on commit efd5187

Please sign in to comment.