mirror of
https://github.com/XRPLF/rippled.git
synced 2026-07-27 09:00:32 +00:00
Review feedback from @gregtatcam: STAmount
- Fix a couple of typos. - Make fewer unneeded copies in roundToScale.
This commit is contained in:
@@ -701,7 +701,7 @@ getRate(STAmount const& offerOut, STAmount const& offerIn);
|
||||
*/
|
||||
STAmount
|
||||
roundToScale(
|
||||
STAmount value,
|
||||
STAmount const& value,
|
||||
std::int32_t scale,
|
||||
Number::rounding_mode rounding = Number::getround());
|
||||
|
||||
@@ -729,7 +729,7 @@ roundToAsset(
|
||||
STAmount const ret{asset, value};
|
||||
if (ret.integral())
|
||||
return ret;
|
||||
// Not that the ctor will round integral types (XRP, MPT) via canonicalize,
|
||||
// Note that the ctor will round integral types (XRP, MPT) via canonicalize,
|
||||
// so no extra work is needed for those.
|
||||
return roundToScale(ret, scale);
|
||||
}
|
||||
|
||||
@@ -1462,9 +1462,12 @@ canonicalizeRoundStrict(
|
||||
}
|
||||
|
||||
STAmount
|
||||
roundToScale(STAmount value, std::int32_t scale, Number::rounding_mode rounding)
|
||||
roundToScale(
|
||||
STAmount const& value,
|
||||
std::int32_t scale,
|
||||
Number::rounding_mode rounding)
|
||||
{
|
||||
// Nothing to do for intgral types.
|
||||
// Nothing to do for integral types.
|
||||
if (value.integral())
|
||||
return value;
|
||||
|
||||
@@ -1474,16 +1477,15 @@ roundToScale(STAmount value, std::int32_t scale, Number::rounding_mode rounding)
|
||||
if (value.exponent() >= scale)
|
||||
return value;
|
||||
|
||||
STAmount referenceValue{
|
||||
STAmount const referenceValue{
|
||||
value.asset(), STAmount::cMinValue, scale, value.negative()};
|
||||
|
||||
NumberRoundModeGuard mg(rounding);
|
||||
// With an IOU, the total will be truncated to the precision of the
|
||||
// larger value: referenceValue
|
||||
value += referenceValue;
|
||||
// Remove the reference value, and we're left with the rounded value.
|
||||
value -= referenceValue;
|
||||
return value;
|
||||
// With an IOU, the the result of addition will be truncated to the
|
||||
// precision of the larger value, which in this case is referenceValue. Then
|
||||
// remove the reference value via subtraction, and we're left with the
|
||||
// rounded value.
|
||||
return (value + referenceValue) - referenceValue;
|
||||
}
|
||||
|
||||
namespace {
|
||||
|
||||
Reference in New Issue
Block a user