[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[lmi-commits] [lmi] valyuta/004 780c7c3 4/6: Improve accuracy when CURRE
From: |
Greg Chicares |
Subject: |
[lmi-commits] [lmi] valyuta/004 780c7c3 4/6: Improve accuracy when CURRENCY_UNIT_IS_CENTS not defined |
Date: |
Thu, 7 Jan 2021 04:30:42 -0500 (EST) |
branch: valyuta/004
commit 780c7c3ec82bc3d1e27994a8c4ac8a517f52e065
Author: Gregory W. Chicares <gchicares@sbcglobal.net>
Commit: Gregory W. Chicares <gchicares@sbcglobal.net>
Improve accuracy when CURRENCY_UNIT_IS_CENTS not defined
Without this change, 'AVSepAcct' was often some minuscule amount like
2.5e-12 due to catastrophic cancellation. With it, regression tests on
this branch (with CURRENCY_UNIT_IS_CENTS not defined) compare nicely
with production, which means that it can be cleaned up and merged with
'master' confidently. Later, defining CURRENCY_UNIT_IS_CENTS will change
some calculations, but it's easier and safer to test the effect of that
single change separately. Thus:
- #undef CURRENCY_UNIT_IS_CENTS: many changes; known minor regressions
- #define CURRENCY_UNIT_IS_CENTS: one change for which code review is
simple; some larger regressions (which correct old behavior that
didn't always round every currency amount).
---
ihs_avmly.cpp | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/ihs_avmly.cpp b/ihs_avmly.cpp
index d9a51a9..8585522 100644
--- a/ihs_avmly.cpp
+++ b/ihs_avmly.cpp
@@ -356,6 +356,10 @@ void AccountValue::IncrementAVProportionally(currency
increment)
currency genacct_increment = round_minutiae().c(increment *
GenAcctPaymentAllocation);
AVGenAcct += genacct_increment;
AVSepAcct += increment - genacct_increment;
+#if !defined CURRENCY_UNIT_IS_CENTS
+ AVSepAcct = round_minutiae().c(AVSepAcct.d());
+ if(0.0 == AVSepAcct.d()) AVSepAcct = C0; // Negate negative zeroes.
+#endif // !defined CURRENCY_UNIT_IS_CENTS
}
//============================================================================
@@ -482,6 +486,10 @@ void AccountValue::DecrementAVProportionally(currency
decrement)
currency genacct_decrement = round_minutiae().c(decrement *
general_account_proportion);
AVGenAcct -= genacct_decrement;
AVSepAcct -= decrement - genacct_decrement;
+#if !defined CURRENCY_UNIT_IS_CENTS
+ AVSepAcct = round_minutiae().c(AVSepAcct.d());
+ if(0.0 == AVSepAcct.d()) AVSepAcct = C0; // Negate negative zeroes.
+#endif // !defined CURRENCY_UNIT_IS_CENTS
}
/// Apportion decrements to account value between separate- and
- [lmi-commits] [lmi] valyuta/004 updated (d4180d4 -> 96d02bc), Greg Chicares, 2021/01/07
- [lmi-commits] [lmi] valyuta/004 ae4fa16 1/6: Restore monthly-trace precision for currency, Greg Chicares, 2021/01/07
- [lmi-commits] [lmi] valyuta/004 96d02bc 6/6: Record timings, Greg Chicares, 2021/01/07
- [lmi-commits] [lmi] valyuta/004 5a29ed5 2/6: Refactor an assertion, Greg Chicares, 2021/01/07
- [lmi-commits] [lmi] valyuta/004 780c7c3 4/6: Improve accuracy when CURRENCY_UNIT_IS_CENTS not defined,
Greg Chicares <=
- [lmi-commits] [lmi] valyuta/004 1f7a1c7 3/6: Note some ideas for future consideration, Greg Chicares, 2021/01/07
- [lmi-commits] [lmi] valyuta/004 4a3e0c2 5/6: Treat RAM as abundant, Greg Chicares, 2021/01/07