[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[lmi-commits] [lmi] master 99aebcc 07/22: Treat decimal_root return valu
From: |
Greg Chicares |
Subject: |
[lmi-commits] [lmi] master 99aebcc 07/22: Treat decimal_root return value more flexibly |
Date: |
Sun, 6 Jun 2021 21:38:00 -0400 (EDT) |
branch: master
commit 99aebcc18a247b4369b4daa97b3dde95b3d0b0f3
Author: Gregory W. Chicares <gchicares@sbcglobal.net>
Commit: Gregory W. Chicares <gchicares@sbcglobal.net>
Treat decimal_root return value more flexibly
At present, enum root_validity has only two values:
{root_is_valid
,root_not_bracketed
};
but it is desirable to add a third, indicating a different mode of
failure, as all successes are similar but failures can have different
causes. Thus, that enumeration wants to be handled in a 'switch'.
Where failure is considered impossible, assert success, instead of
asserting the absence of some type of failure: then the assertion
makes a 'switch' unnecessary.
---
calendar_date.cpp | 2 +-
financial.hpp | 9 ++++++---
ihs_avsolve.cpp | 19 +++++++++++++------
solve.cpp | 13 ++++++++++---
4 files changed, 30 insertions(+), 13 deletions(-)
diff --git a/calendar_date.cpp b/calendar_date.cpp
index 05d5de3..85f51d9 100644
--- a/calendar_date.cpp
+++ b/calendar_date.cpp
@@ -751,7 +751,7 @@ class birthdate_limit
,0
,*this
);
- LMI_ASSERT(root_not_bracketed != z.second);
+ LMI_ASSERT(root_is_valid == z.second);
int j = bourn_cast<int>(z.first);
j = std::min(j, as_of_date_.julian_day_number());
j = std::max(j, a_priori_minimum_);
diff --git a/financial.hpp b/financial.hpp
index edfef5f..5e9d60a 100644
--- a/financial.hpp
+++ b/financial.hpp
@@ -122,12 +122,15 @@ class irr_helper
,decimals_
,*this
);
- if(root_not_bracketed == z.second)
+ switch(z.second)
{
+ case root_is_valid:
+ {return z.first;}
// Return -100% if NPVs of a priori bounds have same sign.
- z.first = -1.0L;
+ case root_not_bracketed:
+ {return -1.0L;}
}
- return z.first;
+ throw "Unreachable--silences a compiler diagnostic.";
}
private:
diff --git a/ihs_avsolve.cpp b/ihs_avsolve.cpp
index 05332b4..1ee549e 100644
--- a/ihs_avsolve.cpp
+++ b/ihs_avsolve.cpp
@@ -468,15 +468,22 @@ currency AccountValue::Solve
// now, and actual values are freshly generated downstream.
(this->*solve_set_fn)(solution_cents);
- if(root_not_bracketed == solution.second)
+ switch(solution.second)
{
- LMI_ASSERT(0.0 == solution.first);
- // Don't want this firing continually in census runs.
- if(!SolvingForGuarPremium)
+ case root_is_valid:
+ {} // Do nothing.
+ break;
+ case root_not_bracketed:
{
- warning() << "Solution not found: using zero instead." <<
LMI_FLUSH;
- // TODO ?? What can we do when no solution exists for guar prem?
+ LMI_ASSERT(0.0 == solution.first);
+ // Don't want this firing continually in census runs.
+ if(!SolvingForGuarPremium)
+ {
+ warning() << "Solution not found: using zero instead." <<
LMI_FLUSH;
+ // TODO ?? What can we do when no solution exists for guar
prem?
+ }
}
+ break;
}
return solution_cents;
}
diff --git a/solve.cpp b/solve.cpp
index 7dfb3c9..ff665bb 100644
--- a/solve.cpp
+++ b/solve.cpp
@@ -347,10 +347,17 @@ currency AccountValue::Solve()
// now, and actual values are freshly generated downstream.
SolveFn(dblize(solution_cents));
- if(root_not_bracketed == solution.second)
+ switch(solution.second)
{
- LMI_ASSERT(0.0 == solution.first);
- warning() << "solution not found. Using zero instead." << LMI_FLUSH;
+ case root_is_valid:
+ {} // Do nothing.
+ break;
+ case root_not_bracketed:
+ {
+ LMI_ASSERT(0.0 == solution.first);
+ warning() << "solution not found. Using zero instead." <<
LMI_FLUSH;
+ }
+ break;
}
return solution_cents;
}
- [lmi-commits] [lmi] master updated (f0526be -> 86661b6), Greg Chicares, 2021/06/06
- [lmi-commits] [lmi] master 7bd1245 01/22: Add a unit test: root of another unfriendly function, Greg Chicares, 2021/06/06
- [lmi-commits] [lmi] master c01b9b0 02/22: Improve concinnity, Greg Chicares, 2021/06/06
- [lmi-commits] [lmi] master 012967c 08/22: Diagnose any attempt to find a root in a zero-measure interval, Greg Chicares, 2021/06/06
- [lmi-commits] [lmi] master 83eb025 05/22: Rename a local variable, Greg Chicares, 2021/06/06
- [lmi-commits] [lmi] master ec0a308 06/22: Refactor, Greg Chicares, 2021/06/06
- [lmi-commits] [lmi] master 99aebcc 07/22: Treat decimal_root return value more flexibly,
Greg Chicares <=
- [lmi-commits] [lmi] master 5c31ab3 09/22: Fix latent unit-test errors, Greg Chicares, 2021/06/06
- [lmi-commits] [lmi] master 2391573 11/22: Rename a variable, for terseness, Greg Chicares, 2021/06/06
- [lmi-commits] [lmi] master b14e318 18/22: Adjust tolerance for a particular unit-test function, Greg Chicares, 2021/06/06
- [lmi-commits] [lmi] master 1c448d8 20/22: Augment decimal_root()'s return type, Greg Chicares, 2021/06/06
- [lmi-commits] [lmi] master 53c3513 21/22: Reorder unit tests, Greg Chicares, 2021/06/06
- [lmi-commits] [lmi] master 5cf534c 04/22: Constify, Greg Chicares, 2021/06/06
- [lmi-commits] [lmi] master 3865416 10/22: Rearrange certain unit tests, Greg Chicares, 2021/06/06
- [lmi-commits] [lmi] master 1f8316c 16/22: Test actual return value, Greg Chicares, 2021/06/06
- [lmi-commits] [lmi] master 3d4adb3 17/22: Clarify, Greg Chicares, 2021/06/06
- [lmi-commits] [lmi] master 200e756 03/22: Clarify documentation, Greg Chicares, 2021/06/06