[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[lmi-commits] [lmi] valyuta/004 7306944 2/4: Fix rounding for whole-doll
From: |
Greg Chicares |
Subject: |
[lmi-commits] [lmi] valyuta/004 7306944 2/4: Fix rounding for whole-dollar currency amounts |
Date: |
Fri, 18 Dec 2020 07:29:52 -0500 (EST) |
branch: valyuta/004
commit 73069441add067dadc8e6173fbbc7f96320acc9e
Author: Gregory W. Chicares <gchicares@sbcglobal.net>
Commit: Gregory W. Chicares <gchicares@sbcglobal.net>
Fix rounding for whole-dollar currency amounts
For 'sample*' products (and for some companies' actual products),
specified amount is rounded to whole dollars. For other currency
amounts, any integral number of cents is okay, and to round an
already-integral amount to the nearest integer, it suffices to pass
it through unmodified; but that's not the case for values such as
specified amount that are to be rounded to whole dollars.
This change is required for correctness, but unfortunately it imposes
a runtime cost of about five percent. That seems outlandish on the
face of it; the reason is that AccountValue::TxSpecAmtChange() is
called extremely often with an argument of zero, even though its
inline documentation says:
// TODO ?? Changing specamt by zero is absurd.
But that's an ancient defect that won't be fixed today.
---
Speed_gcc_i686-w64-mingw32 | 12 ++++++------
round_to.hpp | 4 ++++
2 files changed, 10 insertions(+), 6 deletions(-)
diff --git a/Speed_gcc_i686-w64-mingw32 b/Speed_gcc_i686-w64-mingw32
index ec9d7ad..96434ea 100644
--- a/Speed_gcc_i686-w64-mingw32
+++ b/Speed_gcc_i686-w64-mingw32
@@ -1,7 +1,7 @@
Test speed:
- naic, no solve : 6.199e-02 s mean; 61318 us least of 17 runs
- naic, specamt solve : 1.093e-01 s mean; 108222 us least of 10 runs
- naic, ee prem solve : 1.001e-01 s mean; 99517 us least of 10 runs
- finra, no solve : 2.358e-02 s mean; 23235 us least of 43 runs
- finra, specamt solve: 6.669e-02 s mean; 65938 us least of 15 runs
- finra, ee prem solve: 6.192e-02 s mean; 61419 us least of 17 runs
+ naic, no solve : 6.500e-02 s mean; 64214 us least of 16 runs
+ naic, specamt solve : 1.158e-01 s mean; 113670 us least of 9 runs
+ naic, ee prem solve : 1.047e-01 s mean; 103533 us least of 10 runs
+ finra, no solve : 2.501e-02 s mean; 23474 us least of 40 runs
+ finra, specamt solve: 6.883e-02 s mean; 67903 us least of 15 runs
+ finra, ee prem solve: 6.379e-02 s mean; 63007 us least of 16 runs
diff --git a/round_to.hpp b/round_to.hpp
index 443fdcb..9b924f3 100644
--- a/round_to.hpp
+++ b/round_to.hpp
@@ -439,6 +439,10 @@ inline currency round_to<RealType>::c(currency z) const
{
LMI_ASSERT(decimals() <= 2); // ROUNDING similarly restrict rounding_rules
// instead, this ought to verify proper rounding
+ if(decimals() < 2)
+ {
+ z = c(z.d());
+ }
return z;
}