Start converting Loans to use fixed payments and track value

- Not expected to build
This commit is contained in:
Ed Hennis
2025-10-01 20:09:48 -04:00
parent d353f4a2e6
commit 63edf035a6
13 changed files with 353 additions and 305 deletions

View File

@@ -1510,32 +1510,28 @@ canonicalizeRoundStrict(
}
STAmount
roundToReference(
STAmount const value,
STAmount referenceValue,
Number::rounding_mode rounding)
roundToScale(STAmount value, std::int32_t scale, Number::rounding_mode rounding)
{
// Nothing to do for intgral types.
if (value.asset().native() || !value.asset().holds<Issue>())
return value;
// If the value is greater than or equal to the referenceValue (ignoring
// sign), then rounding will do nothing, so just return the value.
if (value.exponent() > referenceValue.exponent() ||
(value.exponent() == referenceValue.exponent() &&
value.mantissa() >= referenceValue.mantissa()))
// If the value's exponent is greater than or equal to the scale, then
// rounding will do nothing, and might even lose precision, so just return
// the value.
if (value.exponent() >= scale)
return value;
if (referenceValue.negative() != value.negative())
referenceValue.negate();
STAmount 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
STAmount const total = referenceValue + value;
value += referenceValue;
// Remove the reference value, and we're left with the rounded value.
STAmount const result = total - referenceValue;
return result;
value -= referenceValue;
return value;
}
namespace {