From 7b69ed15acf0dc8547dd43926e857dececb84f9c Mon Sep 17 00:00:00 2001 From: Vito <5780819+Tapanito@users.noreply.github.com> Date: Wed, 19 Nov 2025 10:44:01 +0100 Subject: [PATCH] documents why multiplication is performed first --- src/xrpld/app/misc/detail/LendingHelpers.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/xrpld/app/misc/detail/LendingHelpers.cpp b/src/xrpld/app/misc/detail/LendingHelpers.cpp index 13664b5b89..78c23f9a80 100644 --- a/src/xrpld/app/misc/detail/LendingHelpers.cpp +++ b/src/xrpld/app/misc/detail/LendingHelpers.cpp @@ -252,8 +252,11 @@ loanAccruedInterest( auto const secondsSinceLastPayment = parentCloseTime.time_since_epoch().count() - lastPaymentDate; - return principalOutstanding * periodicRate * - (secondsSinceLastPayment / paymentInterval); + // Division is more likely to introduce rounding errors, which will then get + // amplified by multiplication. Therefore, we first multiply, and only then + // divide. + return principalOutstanding * periodicRate * secondsSinceLastPayment / + paymentInterval; } /* Applies a payment to the loan state and returns the breakdown of amounts