[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[lmi-commits] [lmi] master 873c574 6/8: Expunge an unneeded overload
From: |
Greg Chicares |
Subject: |
[lmi-commits] [lmi] master 873c574 6/8: Expunge an unneeded overload |
Date: |
Fri, 9 Jul 2021 01:41:18 -0400 (EDT) |
branch: master
commit 873c574c6e944a028c97be13a59532f04e844eaa
Author: Gregory W. Chicares <gchicares@sbcglobal.net>
Commit: Gregory W. Chicares <gchicares@sbcglobal.net>
Expunge an unneeded overload
An overload like irr(container) or irr(begin,end) seems obviously
desirable--it's what spreadsheets offer--so why not provide it here?
One reason is that lmi doesn't use it. Instead of
IRR(vector) -> scalar
illustrations really need IRR columns
IRR(vector payments, vector benefits) -> vector
where both input vectors are typically positive.
Another reason is that the expunged implementation was flawed. It had
been implemented in terms of a helper that assumed it would receive
(typically positive) payments and benefits separately--unlike the
spreadsheet function, which typically operates on a vector containing
(at least) one negated value. To adapt the helper to that use case,
the last element of a {pmt0, pmt1, ... pmtN, bft} vector could have
been extracted, un-negated, and passed as a distinct argument; instead,
as a nonchalant expedient, a zero had been appended, causing -100% to
be a root in every case. An attempt to repair the expunged overload by
un-negation proved correct, but too ugly--if such an overload is wanted,
it should be implemented in a straightforward way, but that's too much
work for an overload that lmi doesn't even use.
---
financial.hpp | 10 ----------
financial_test.cpp | 10 ++--------
2 files changed, 2 insertions(+), 18 deletions(-)
diff --git a/financial.hpp b/financial.hpp
index d03390c..242e43f 100644
--- a/financial.hpp
+++ b/financial.hpp
@@ -133,16 +133,6 @@ long double irr
return irr_helper<InputIterator>(first, last, x, decimals)();
}
-template<typename InputIterator>
-long double irr
- (InputIterator first
- ,InputIterator last
- ,int decimals
- )
-{
- return irr_helper<InputIterator>(first, last, 0.0L, decimals)();
-}
-
template
<typename InputIterator0
,typename InputIterator1
diff --git a/financial_test.cpp b/financial_test.cpp
index 423739c..fa0b167 100644
--- a/financial_test.cpp
+++ b/financial_test.cpp
@@ -147,14 +147,8 @@ int test_main(int, char*[])
LMI_TEST_EQUAL(-6400.0 , fv(cash_flows + 0, cash_flows + 4, 1.0 ));
// Test with vectors.
-#if 0
- // For the nonce, these tests fail. The first one in particular
- // is just asking for trouble: it's designed to have a root of
- // 200%, but appending "0.0" ensures that -100% is also a root.
- std::vector<double> v(cash_flows, 4 + cash_flows);
- LMI_TEST_EQUAL(2.0, irr(v.begin(), v.end(), 0.0, 5));
- LMI_TEST_EQUAL(2.0, irr(v.begin(), v.end(), 5));
-#endif // 0
+ std::vector<double> v(pmts, 3 + pmts);
+ LMI_TEST_EQUAL(2.0, irr(v.begin(), v.end(), bfts[2], 5));
std::vector<double> p; // Payments.
std::vector<double> b; // Benefits.
- [lmi-commits] [lmi] master updated (55873f1 -> ce8b814), Greg Chicares, 2021/07/09
- [lmi-commits] [lmi] master 485d642 4/8: Augment unit tests, Greg Chicares, 2021/07/09
- [lmi-commits] [lmi] master be56aad 2/8: Move and rename a present-value function, Greg Chicares, 2021/07/09
- [lmi-commits] [lmi] master 873c574 6/8: Expunge an unneeded overload,
Greg Chicares <=
- [lmi-commits] [lmi] master ac0da7b 3/8: Use a more appropriate unit-test macro, Greg Chicares, 2021/07/09
- [lmi-commits] [lmi] master 951a9c9 1/8: Improve IRR speed measurements, Greg Chicares, 2021/07/09
- [lmi-commits] [lmi] master 81ede74 5/8: Reimplement fv(), Greg Chicares, 2021/07/09
- [lmi-commits] [lmi] master ce8b814 8/8: Record speed measurements, Greg Chicares, 2021/07/09
- [lmi-commits] [lmi] master 7c21f2a 7/8: Optionally trace IRR iterations, Greg Chicares, 2021/07/09