lmi-commits
[Top][All Lists]
Advanced

[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.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]